How to Setup Apex Remote with OmniStudio FlexCards

Learn how to use Apex Remote from FlexCard and OmniScripts and what is required for the Apex class.

Sample code for the Apex Remote class can be found on github here.

To use Apex Remote, you need to define the class then you can select this as a Data Source type when creating a FlexCard or OmniScript.

Creating an Apex Remote Class For OmniStudio

First create an Apex Class that implements the VlocityOpenInterface.

global class AccountRemoteClass implements vlocity_cmt.VlocityOpenInterface 

Add the default implementation method invoke

global Boolean invokeMethod(String methodName, Map<String,Object> inputMap, Map<String,Object> outMap, Map<String,Object> options)

Method Details

  • methodName – name of the method to be called
  • inputMap – key/value map passed to the class
  • outMap – key/value map to return as part of the response
  • options – key/value map

Create a try/catch that calls the method and returns the Boolean value

Boolean result = false;
try {
       // check methodName
       if(methodName == 'getAccountRecords') {
	  result = true;
} catch(Exception e) {
        system.debug('The error is ' + e.getMessage());
return result;

Next, create your method and set the outMap.

private void getAccountRecords(Map<String,Object> outMap) {
        List<Account> accountList = [SELECT Id, Name, Website, Phone FROM Account LIMIT 10];
        outMap.put('account', accountList);

Using The Apex Remote From FlexCard

Create a new FlexCard from OmniStudio FlexCard Designer

  • From the Data Wizard or the Setup Panel select Apex Remote as Data Source Type
  • Provide a Remote Class – AccountRemoteClass
  • Provide a Remote Method – getAccountRecords
  • Optionally provide Is Async and Poll Interval
  • Add InputMap or OptionsMap
  • Result JSON Path – set to [“account”]

Add a Text Field to the Canvas and populate with the field results

Run the Preview and it should display the data.

Hope you like this post. I’ll be coming up with a newsletter soon to deliver the fresh tips and tricks.

One thought on “How to Setup Apex Remote with OmniStudio FlexCards

Leave a Reply

Your email address will not be published. Required fields are marked *