How to Setup Apex REST with OmniStudio FlexCards

Learn how to use Apex REST from FlexCard and OmniScripts and what is required for the Apex class.  On a previous post I covered using Apex Remote for FlexCards if that is what you are looking for go checkout that tutorial.

The use case is straightforward, I want the flex card to display the list of contacts under an account. So what this entails is.

  • Simple Apex REST service supporting GET Method
  • Flex Card with Data Source of Apex Rest

Apex REST Steps

First create a new apex class, add the @RestResource annotation and define the urlMapping

@RestResource(urlMapping='/flexCard/*')

Next create a method annotated with @HttpGet and grab the record Id and start querying for the related contacts.

Tip: Use String InstanceOf Id to check if recordId is actually valid.

Flex Card Steps

Create a new FlexCard and provide the required Name, Title, Theme and Author.

For the data source type select Apex REST and hit Next

Fill in the required details

  • Endpoint – the Salesforce REST endpoint.
    • eg. /services/apexrest/flexCard/{recordId}
  • Method – have a think which method works for your use case. When will you use a POST on a Flex Card.
    • eg. GET
  • JSON Payload – Only needed when you use POST
  • Options – you can order the results.

Output

Add an account Id record as a test parameter to test it out. Then you can build the UI with the Flex Card elements with the data returned.

Summary

So now you learned how to use Apex REST as another data source for Flex Card. Think about the use cases for the Apex REST. It is more suitable for complex data types.

Simple query you can use the normal SOQL query data source type.

Leave a Reply

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