Omnistudio : Invoke Omnistudio IntegrationProcedure Calls from LWC
Introduction
Salesforce's Omnistudio offers amazing tools for creating guided workflows and dynamic business processes. One of the coolest features in Omnistudio is the Integration Procedure, which lets you call external systems or handle data within Salesforce. In this blog, we'll dive into how to make Omnistudio Integration Procedure calls right from a Lightning Web Component (LWC).
Prerequisites
Before we jump into the implementation, make sure you have the following:
A basic understanding of Lightning Web Components (LWC)
Familiarity with Salesforce Omnistudio and its Integration Procedures
A Salesforce org with Omnistudio enabled
Setting Up the LWC
Let's start by creating a simple LWC that will call an Integration Procedure. Here’s the code for the component:
<template>
<lightning-button class="slds-p-around_medium" onclick={callAPI} variant="neutral" label="Call To API"></lightning-button>
</template>
import {LightningElement} from 'lwc';
import {OmniscriptActionCommonUtil} from 'omnistudio/omniscriptActionUtils';
import {OmniscriptBaseMixin} from 'omnistudio/omniscriptBaseMixin';
export default class DemoCallIpFromLwc extends OmniscriptBaseMixin(LightningElement) {
_actionUtilClass;
connectedCallback() {
this._actionUtilClass = new OmniscriptActionCommonUtil();
}
callAPI(event) {
event.preventDefault();
this.isPageLoading = true;
const options = {
chainable: false,
useFuture: false,
};
const params = {
input: JSON.stringify({}),
sClassName: 'omnistudio.IntegrationProcedureService',
sMethodName: 'Util_FetchAPIData', //this will need to match type_subtype from IP
options: JSON.stringify(options),
};
this._actionUtilClass
.executeAction(params, null, this, null, null)
.then(resp => {
this.isPageLoading = false;
console.log('resp => ' + JSON.stringify(resp))
})
.catch(error => {
this.isPageLoading = false;
console.error('error => ' + JSON.stringify(error));
});
}
}
The IP which I created here just does a callout, but this can be any logic.
This way, you don't have to write any Apex class for doing server-side logic from LWC.
Testing the LWC
Deploy this component and add it to a Lightning page. Make sure the Integration Procedure exists in your Salesforce org and is set up correctly. When you trigger the callAPI
method (for example, by clicking a button), the Integration Procedure will run, and you'll see the results in the browser console.
Conclusion
This blog gave you a step-by-step guide on how to call an Omnistudio Integration Procedure call in LWC. With this method, you can easily connect to external systems and handle data within Salesforce, using the strengths of both Omnistudio and Lightning Web Components.