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.

Transmit NBA Errors to Custom Notification Targets

When we built Next Best Action, we set things up to fire a platform event whenever an error occurs. You can leverage Process Builder and Flow to create custom notification profiles that flexibly get error messages to where you want them. Learn more.

Next Best Action: What’s a Request?

Next Best Action is a paid Salesforce product but also is available for free use for up to 5000 requests each month.

What is a Request and how do they get generated?
A ‘request’ is a call to the NBA engine that causes an NBA ActionStrategy to run and return some recommendations. The primary way these requests are made is via the placement of the Einstein Next Best Action lightning component on a record page in App Builder or via the placement of the Suggested Actions community builder component on a Community page:

Each time a page with an NBA component is loaded into a web browser, a new request will be generated.

The secondary way requests are made is by calling the NBA endpoint from some other piece of software, such as an IOS or Android native app. An app that does this will make requests in response to custom UI, and get back the recommendation information as text that it is then responsible to present.

A request is also made when i) a record detail page includes the Next Best Action component and a record field is updated and ii) when the communities contact support page includes the Next Best Action component as the user types in the subject/description fields.

Where Can I See My Usage?

Look in Setup —> Company Information.

Learn More: Try out Next Best Action via this video tutorial.

The Top 10 Things You Want To Know About New Next Best Action

1. Generally Available

Next Best Action (NBA) is generally available starting today and the great news is that it’s enabled for all editions. But wait it gets better – every org receives 5000 requests per month for free!

2. Here’s the Getting Started Video

Ok, you heard that it’s free and it sounds very cool, how do you get started? Here is a great video to get the ball rolling.

3. Documentation is online

Need more information about Next Best Action? Here is some ever-improving documentation.

4. This post is part of a new, unofficial, community-powered site that hosts Next Best Action content

This will be a place where you can find tips and tricks, explore interesting use cases, share videos, and more. Here’s the home page. You’ll want to bookmark it for future reference.

5. There are 8 new How To Guides for additional Next Best Action features

Check them out here!

6. Lightning is recommended but not required

The Lightning Experience is not required to run NBA but it is recommended. Now, you’ll need Lightning to build NBA action strategies using the Strategy Builder. However, you can display recommendations on both Lightning and Classic experiences. With Lightning, simply use the out-of-the-box Einstein Next Best Action Lightning Component. With Classic, present your recommendations via VisualForce using Lightning Out. Want to learn more? Check this out.

7. You can add additional request capacity to your Org

If you love the product (and we just know you will) and want more requests, just contact Salesforce. What is a request, you might ask. A request is simply page loads and refreshes which result in your strategy being evaluated for recommendations.

8. Testing your strategies is easy

Like all good things, building the right strategy requires some trial and error. You can quickly test your logic and make sure you’re loading the right recommendations by clicking Test in the Strategy Builder. To learn more, check out this doc.

9. Recommendations can be displayed in a variety of places

Once you’ve built your strategy, you can embed recommendations in any app and even in a Community portal.

10. Early customer feedback shows tremendous productivity gains

We’ve already seen some early customer success stories and anticipate more in the coming weeks. One of our pilot customers, a European electronics company, experienced a 90% drop in agent hold times after adding Next Best Action. Before NBA, agents would spend almost 8 minutes and 9 painful clicks sourcing and pulling information before determining whether a customer was eligible for a special discount. With NBA, in less than 1 minute and with only 1 painless click, agents instantly know whether the customer is eligible and can quickly walk through a Flow to offer the discount.

New Guide: Use NBA with Visualforce

Click ‘Read More’ below.

New Guide: Use NBA with Salesforce Connect

To use External Object/Salesforce Connect in a Strategy there are a couple of steps you need to follow.

Learn more.

New Guide: Generating Response Reports in Next Best Action

You can do the following in NBA:

  1. Examine the Acceptance rates of propositions using standard Salesforce reporting tools
  2. Prevent Re-offers by leveraging the tracking of propositions exposed to a particular context target

Learn more.

Deployment Options and Roadmap for Next Best Action

In Spring ’19, you can deploy Next Best Action strategy metadata by using SFDX or Workbench, but there’s no support for unamanaged and managed packages and change sets. These will be supported in Summer ’19

New Guide: Using $User and $Request in Strategies

In addition to $Record, which is described here, there are two other system variables that can be used in Next Best Action.

Learn More.