Show Personalized Recommendations in Flows

Enhance your users' experience by embedding personalized recommendations directly within Salesforce Flows using the Get Personalization Decisions invocable action. This action uses the Personalization Decisioning API to retrieve tailored suggestions based on contact information. By configuring the input parameters and using the provided Apex classes, you can show relevant content, product recommendations, or service solutions within your record pages, agent consoles, and other Flow-driven processes.

This example describes how to use the Get Personalization Decisions invocable action to configure a flow that retrieves and displays personalized recommendations for a contact record.

Before you begin, make sure you have:

  1. From Setup, in the Quick Find box, enter Flows.
  2. Select Flows and then New Flow.
  3. Select Start from Scratch and click Next.
  4. Select Screen Flow and then click Create.

To map values from your contact record and personalization point to the Get Personalization Decisions action and then show the result to a screen, add the default Apex classes to your Flow.

  1. Open the Toolbox and click New Resource.

  2. From the Resource Type dropdown, select Variable.

  3. Provide an API Name. For example, persnlDecInpRep.

  4. From the Data Type dropdown, select Apex-Defined.

  5. Leave Allow multiple values (collection) unchecked.

  6. Search for and select the Apex class ConnectApi__PersnlDecisionInputRepresentation.

  7. Check Available for input and then click Done. Create an Apex-defined Variable

  8. Repeat the preceding steps to create these resources.

    Apex ClassExample API NamePurpose
    ConnectApi__PersnlDecisionOutputRepresentationpersnlDecOutRepTo reference personalized data, recommendations, and diagnostics information when displaying the output to a Contact record.
    ConnectApi__PersnlPointInputRepresentationpesrnlPointVariableVariable for personalization point names.

To pass the Contact’s ID through the Flow a variable is needed to store it.

  1. Click New Resource.
  2. From the Resource Type dropdown, select Variable.
  3. Under API Name, enter recordId.
  4. From the Data Type dropdown, select Record.
  5. Under Object, search for and select Contact.
  6. Check Available for input and then click Done.

Assign the ID from the Contact to the variable. This variable will be used to find the Unified Individual in Data Cloud.

  1. After the Screen Flow element, add an Assignment element.
  2. Enter a Label and API Name.
  3. Under Variable, search for and select the Flow global variable for Current Record {!$Flow.CurrentRecord}.
  4. For Operator, leave Equals selected.
  5. Under Value, choose the variable you created for the Contact resource {!recordId.Id}.

For more information on adding record context to your flows, see Add Record Context to Your Flows. For considerations to keep in mind before using flow actions, see Flow Action Considerations.

For your flow to correctly identify and reference the specific personalization point you’ve configured, you’ll need to add personalization point resources.

  1. Open the Toolbox and click New Resource.
  2. From the Resource Type dropdown, select Variable.
  3. Enter an API Name. For example, PersnlPoint_ApiName_Action_Input.
  4. From the Data Type dropdown, select Text.
  5. Set Default Value to the API name of your personalization point, and then click Done.
  1. Add a Get Records element after the Assignment element. This element finds the unified individual data from Data Cloud that matches the contact information.
  2. For Label, enter Get Unified Individual for Contact Record.
  3. Select Data Cloud Object as the Data Source.
  4. Use the Data Space dropdown to select the data space you’d like to use.
  5. Under Object, search for and select your unified individual data model object (DMO). For example, Unified Individual.
  6. For Condition Requirements, select All Conditions Are Met (AND).
  7. Under Field, search for and select the field that represents a contact’s first name. For example, ssot__FirstName__c.
  8. For Operator, select Equals.
  9. For Value, select the variable for the contact record and the attribute for First Name: {!recordId.FirstName}.
  10. Click Add Condition.
  11. Under Field, search for and select the field that represents a contact’s last name. For example, ssot__LastName__c.
  12. For Operator, select Equals.
  13. For Value, select the variable for the contact record and the attribute for Last Name: {!recordId.LastName}.
  14. Leave the rest of the configuration as is.
  1. Add another Get Records element after the Get Records element for unified individual data. This Get Records element finds the unified link individual from Data Cloud that matches the contact information.
  2. For Label, enter Get Unified Link Individual.
  3. Select Data Cloud Object as the Data Source.
  4. Use the Data Space dropdown to select the data space you’d like to use.
  5. Under Object, search for and select your unified link individual DMO. For example, Unified Link Individual.
  6. For Condition Requirements, select All Conditions Are Met (AND).
  7. Under Field, search for and select the unique ID for the Unified Individual: UnifiedRecordId__c
  8. For Operator, select Equals.
  9. For Value, search for and select the Unified Individual ID that is retrieved from the record fetched by the Get Records element for Unified Link Individual: {!Get_Unified_Individual.ssot__Id__c}.

Follow these steps to map the individualID you retrieved from Data Cloud and the personalization point from the input screen to ConnectApi__persnlDecisionInputRepresentation.

  1. Add an Assignment element after the Get Records element for Unified Link Individual ID.
  2. For Label, enter Personalization Point and Individual ID Assignment.
  3. Under Set Variable Values, configure these assignments:
    AssignmentOperatorExample Assignment
    Assign the Apex-defined variable for personalization point name (the one associated to the Apex Class ConnectApi__PersnlPointInputRepresentation) to the personalization point resourceEquals{!pesrnlPointVariable.persnlPointName} Equals {!PersnlPoint_ApiName_Action_Input}
    Assign the list of personalization points from the Apex-defined variable for ConnectApi__PersnlDecisionInputRepresentation to the variable for personalization point namesAdd{!persnlDecInpRep.personalizationPoints} Add {!pesrnlPointVariable}
    Assign context.individualId from the Apex-defined variable for ConnectApi__PersnlDecisionInputRepresentation to the unified individual ID retrieved by the second Get Records elementEquals{!persnlDecInpRep.context.individualId} Equals {!Get_Unified_Individual.ssot__Id__c}

Next, pass in the variable you created in the previous step into the Get Personalization Decisions invocable action.

  1. Search for and add a Get Personalization Decisions invocable action after the Assignment element.
  2. Enter a Label.
  3. In the Personalization Decision Input field, select the Apex resource you created for the ConnectApi__PersnlDecisionInputRepresentation Apex class.
  4. Enable Included with Specified Value.
  5. Under Invocation Type, enter FLOW.
  6. Expand Show advanced options.
  7. Check Manually assign variables.
  8. In the Personalization Decision Output field, select the Apex resource created for the ConnectApi__PersnlDecisionOutputRepresentation Apex class.

To process the personalized recommendations retrieved by the Get Personalization Decisions invocable action, add two Loops to the flow. The first loop iterates through the persnlDecisionOutputRepresentation.personalizations collection. Then, the second loop delves deeper, iterating through the persnlRecommendations array within each personalization object to access the specific recommendations tied to each personalization point. This approach ensures that your flow can efficiently extract and show all relevant recommendations on the Contact page.

  1. Add the first Loop element after the Get Personalization Decisions action.
  2. Provide a Label. For example, Loop1.
  3. Under Collection Variable, select {!persnlDecisionOutputRepresentation.personalizations to loop through the collection.
  4. Specify the direction for iterating over the collection as you deem appropriate.
  5. Add another Loop element immediately after the first Loop.
  6. Provide a Label.
  7. Under Collection Variable, select the collection variable from your first loop. For example, {!Loop1.persnlRecommendations}.
  8. Specify the direction for iterating over the collection.

In this step, you’ll add a Screen element to show the personalized recommendations to your users on the Contact page.

  1. Add a Screen element after the second Loop and label it.

  2. Add a Repeater component to the canvas and provide an API Name.

  3. Drag a Display Text component within the Repeater component and provide an API Name.

  4. Use the Insert a resource… field to search for and insert resources to show your recommendations as shown in this example.

    This example uses resource names and values referenced in this article.

  5. Save and Activate your flow.

Finally, to add recommendations to your Contact page, edit the page by following these instructions.

  1. Exit Flow Builder and go to Contacts.
  2. Click any contact.
  3. Click the settings cog and then click Edit Page.
  4. Drag the flow component you created onto the page canvas.
  5. Select the flow you just created.
  6. Check Pass all field values from the record into this flow variable.
  7. Click Save.

A fully configured flow that retrieves and displays personalized recommendations for a contact record looks like this.

Fully-configure Flow that retrieves and displays personalized recommendations