Using Next Best Action with Salesforce Connect
To use External Object/Salesforce Connect in a Strategy there are a couple of steps you need to follow.
Set up external data source
- To set up an OData backed ExternalObject follow steps under “Connect an External Data Source” in the Trailhead
- To set up a Custom Apex backed External Object you need to follow the steps here: Set Up Salesforce Connect to Access External Data with a Custom Adapter.
- Apex classes are created in setup under “Apex Classes”
- Here you can find example DataSource.Connection and DataSource.Provider classes with hardcoded data: Custom Apex data source example.
Reference the external data from the context object
- Create a custom field on the context entity (e.g. Case).
- Go to Setup -> Object Manager -> Case -> Field & Relationships
- Add an external lookup field to your external data
- Remember the name of the field as you’ll need it in your strategy definition below.
- Populate the new field on your context objects
- Go to each of the records (e.g. Cases) you want to use and populate the field with the ExternalId of the External Objects in the data source you’re using.
- You can find the ExternalId either by creating a tab for the externa object and checking in the UI or easier by querying through soql in workbench:
SELECT ExternalId FROM <ExternalObjectName>__x
Reference the external data from a Recommendation
This is done in the same way as referencing the external data from the context object but you add the external lookup field to the Recommendation entity instead of the Case.
Use the external data in your strategy’s Filter and Branch Select nodes
Format:
$Record.<ContextLookupField>__r.<ContextDataField>__c == <PropositionLookupField>__r.<PropositionDataField>__c
Where
- <ContextLookupField> is the external lookup field on the context object (e.g. Case) you created above.
- <ContextDataField> is one of the fields on the object that is related to the context.
- <PropositionLookupField> is the external lookup field on the Recommendation object you created above.
- <PropositionDataField> is one of the fields on the object that is related to the proposition.
- __r signifies that it is a custom/external relationship.
- __c signifies that it is a custom field which is needed for all fields except the Id and ExternalId fields which are the only standard fields on External Objects.
Note 1: If the external data is more appropriate on some parent object of your context object, e.g. the Contact of the Case, if it is data about the customer, then you add the external lookup field on the Contact object. Then you access it like this instead: $Record.Contact.<ContextLookupField>__r.<ContextDataField>__c
Note 2: You can also use the external object directly as the context object in which case you access it like this instead:
$Record.<ContextDataField>__c
Note 3: The process its the same for custom objects. Just skip the external data source setup and use a lookup field instead of a external lookup field.