Building Your Own Next Best Action Front End

You aren’t limited to using the lightning components that Salesforce has provided for displaying recommendations. You can POST your own execution calls to the Action Strategy Engine REST endpoint and get back recommendations as a JSON blob.

Executing a Strategy

To execute a strategy use one of the supported endpoints.

It’s recommended that you provide a contextRecord ID, although if your strategy doesn’t have any $Record references, it will not be used. Here’s an example of a POST body:

{    "strategyContext":
{ "key1": "val1",
"key2": "val2" },
"contextRecordId": "a0lB0000001G2nFIAS",
"maxResults": 5
}

Note the strategyContext section in the above example. This powerful mechanism allows you to pass in additional context that you can then reference in your strategy’s expressions. There’s currently no way to configure these additional values in the standard Next Best Action components but when you’re making your own REST calls, you can provide all you want.

Handling the Response

The JSON response will include an array of recommendations and some general information such as error text.

Each recommendation in the array contains all of the information typically used by the Next Best Action component to display the recommendation.

Each recommendation will include a reference to a screen flow. If you want to run the screen flow you’ll want to incorporate the lightning:flow component into your solution and pass it the name of the flow and any parameters. Alternatively, you can encode action information into custom fields of the recommendation. Example: You have two recommendations: “Buy Fish Food from Amazon” and “Buy Tools from Amazon”. You’re using these recommendations in a custom Amazon ordering application. You add a custom field to your Recommendation object called “Product” and store ‘Fish Food’ on one and ‘Tools’ on the other. When you programmatically call the NBA engine, you get back the Buy Fish Food from Amazon recommendation. Part of that response includes the recommendation ID. You then query for that recommendation and read the value of its Product field. You now have the value that your private Amazon ordering system needs to automatically order.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply