Creating NBA Recommendations from Salesforce Records

Sometimes you want to generate recommendations from records. For example, you might want to recommend a set of Accounts that should be worked on, or a set of Leads that should be processed. You can load records of any type using the Load Element. Here, for example, a set of Asset records are loaded in:

If this isn’t the exact set you want to recommend, you can proceed to use the Filter and Sort elements to filter down the initial load.

Once you have the final set of records, you need to convert them to Recommendations. This is necessary because of the expectations of the consumers of your strategy. The consumer is usually the out-of-the-box Next Best Action component:

…but may also be a REST or Apex query.

All of these downstream consumers expect recommendation data structures with the following key fields:

  • a Name
  • an Accept Label
  • a Reject Label
  • an ActionReference, which should be the name of the flow that should be run when the user selects Accept or Reject
  • a Description

Note that the only required fields are ActionReference and Description. The Description field, which is not normally a required field in Salesforce, is shown above in the image as ‘0% Refinancing….’. The recommendation in the image above doesn’t actually have a Name showing but it needs that Description.

It’s also essential that the flow you point you be a Screen Flow and be Active.

Using the Map Element to Convert Records into Recommendations

You have to use the Map element to assemble recommendation objects that correspond to the records that your want to recommend. Let’s look at that. In our example above, we use Load Element to load Asset records. They do not have fields like AcceptLabel or ActionReference. They do, however, have a Name field and a Description field, like most Salesforce object types.

Here’s an example of an Asset record with a Name and a Description:

Note that this org has 5 different products with the AssetName ‘DellGrey’ but only the one above has a Description.

Let’s build a minimal Map element:

Things to note:

  1. the name of the flow is in quotes. Anything that’s not in quotes is assumed to be a field.
  2. the meaning of the second mapping is: for each record being passed into this Map element, take the value of its Description field and copy that into the Description field of a corresponding Recommendation.
  3. If a source field is empty, the record will be filtered out by the Map element.

That means that, because only one of the 5 assets loaded by the Load element has a Description value, we expect to see only a single recommendation generated by the Map element when we click the Test button, and that’s what indeed happens:

At this point you might reasonably say ‘why the hell did Opportunity just show up’? The simple reason is that I didn’t build this demo and am too lazy to clean it up. A more useful explanation: All NBA strategies must run against a context record. Think of this as often being the record page where the recommendations will show up. This particular strategy uses Opportunity as a context record, and in order to run Test Strategy, we need to provide an actual opportunity. If you go up to the Load Records example at the top of the page, you’ll see that the Load criteria ignore the Opportunity ID. This is therefore not very realistic. More likely, a real strategy would either incorporate the id of the context record into that initial query or be used in a Filter element or Branch Select element.

Why does the Accept button say “DellGrey”. That’s a bug that we can work around by adding a static value to our Mapping:

…which leads to:

You can use formulas to modify field data as part of the mapping and can incorporate fields from the context records. For more information see:

How To: Use the Map Element in the Strategy Builder