Access Data Cloud from Flows
Learning Objectives
After completing this unit, you’ll be able to:
- Create a record-triggered flow.
- Retrieve data model object (DMO) data in a flow.
In Flow Builder, you can use the Get Records element in any flow to retrieve data from any data model object (DMO) or calculated insight object (CIO). With this ability, your flows can access data from any of your external data sources, such as preferred identity or contact information, loyalty program status, web-based purchases, mobile app activity, and more.
Your new Data Cloud playground (the one you created in the previous unit) is set up to resemble Coral Cloud Resort’s Salesforce org and their new Data Cloud installation. In these exercises and hands-on challenges, you work with DMOs and CIOs that simulate Coral Cloud Resort’s guest data, reservations, and shopping behaviors.
Create a Flow to Retrieve Data from a Data Model Object
Let’s look at an example of how to access DMO data in a flow. As a member of Coral Cloud Resort’s Salesforce admin team, you’re responsible for data accuracy in your Salesforce org. In this org, the Contacts object contains your guest records, but there’s also an external guest database outside of Salesforce. To keep these two groups of data aligned, the Contact object’s External ID field contains the unique ID of the same person in the external guest database.
Today, your team keeps this External ID field up-to-date on every contact manually. That’s prone to human error and also tedious. So let’s automate setting the External ID when a contact is created. The guest’s email address is the most consistent commonality between the Salesforce contacts and the external guest records, so use the email address to line up the records. And while you’re at it, check if the contact’s phone number is blank; if so, fill it in from the external guest information.
Fortunately, the email address, phone number, and unique external ID are all found in the Contact Point objects, such as Contact Point Phone and Contact Point Email. The Contact Point objects don’t have a field called “External ID”, but Coral Cloud has mapped the guests’ unique IDs to the Contact Point objects’ Party field.
For this flow, you retrieve from the external guest data source the Contact Point Email record that has the new contact’s email address. Then, if the contact’s phone number is:
- Blank:
- Retrieve the Contact Point Phone record that has the same Party value as the Contact Point Email.
- Update the new contact’s External ID with the Party value.
- Update the contact’s Phone with the phone number from the Contact Point Phone record.
- Retrieve the Contact Point Phone record that has the same Party value as the Contact Point Email.
- Not blank: Update the new contact’s External ID with the Party value.
- From Setup, enter
Flows
in the Quick Find box and then click Flows.
- Click New Flow.
- Make sure Start from Scratch is selected, and click Next.
- Select Record-Triggered Flow and click Create.
- In the Configure Start panel:
- For Object, select Contact.
- For Trigger the Flow When, select A record is created.
- For Condition Requirements, select All Conditions Are Met (AND).
- In the condition requirement fields:
- For Field, select Email.
- For Operator, select Is Null.
- For Value, select $GlobalConstant.False.
- For Field, select Email.
- Click Add Condition.
- In the second condition requirement:
- For Field, select External_Id__c.
- For Operator, select Is Null.
- For Value, select $GlobalConstant.True.
- For Field, select External_Id__c.
- Make sure Optimize the Flow for is set to Actions and Related Records.
When you retrieve Data Cloud data in a flow, it must be set to Actions and Related Records.
- Check Include a Run Asynchronously path to access an external system after the original transaction for the triggering record is successfully committed.
This setting enables the flow’s Run Asynchronously path. When you retrieve Data Cloud data, it must be in a Run Asynchronously or scheduled path, not in the Run Immediately path.
- For Object, select Contact.
- On the Run Asynchronously path, click .
- Select Get Records.
- For Label, enter
Get CP Email
.
- For API Name, enter
Get_CP_Email
.
- For Data Source, select Data Cloud Object.
- For Data Space, select default.
- For Object, select Contact Point Email.
- For Condition Requirements, select All Conditions Are Met (AND).
- In the condition requirement fields:
- For Field, select ssot__EmailAddress__c.
- For Operator, select Equals.
- For Value, select $Record, then select Email.
- For Field, select ssot__EmailAddress__c.
- Click Add Condition and set these values in the second condition requirement:
- For Field, select ssot__DataSourceObjectId__c.
- For Operator, select Equals.
- For Value, enter
External_Guest__c
.
This value tells the Get Records to only retrieve the Contact Point Email record that comes from the external guest data.
- For Field, select ssot__DataSourceObjectId__c.
- Leave the other fields as default.
- For Label, enter
- After the Get CP Email element, click and add a Decision element.
- For Label, enter
Phone is Blank?
- For API Name, enter
Phone_is_Blank
.
- In the Outcome Details:
- For Label, enter
Yes
.
- For Outcome API Name, enter
Yes
.
- For Condition Requirements to Execute Outcome, select All Conditions Are Met (AND).
- For Resource, select Triggering Contact, then select Business Phone.
The Business Phone field is usually visible on record pages as “Phone”.
- For Operator, select Is Blank.
- For Value, select True.
- For Label, enter
- In the Outcome Order, select Default Outcome.
- For Label, enter
No
.
- For Label, enter
- For Label, enter
- On the Yes path, add a Get Records element.
- For Label, enter
Get CP Phone
.
- For API Name, enter
Get_CP_Phone
.
- For Data Source, select Data Cloud Object.
- For Data Space, select default.
- For Object, select Contact Point Phone.
- For Condition Requirements, select All Conditions Are Met (AND).
- In the condition requirement fields:
- For Field, select ssot__PartyId__c.
- For Operator, select Equals.
- For Value, select Contact Point Email from Get_CP_Email, then select ssot__PartyId__c.
- For Field, select ssot__PartyId__c.
- Leave the other fields as default.
- For Label, enter
- After the Get CP Phone element, add an Update Records element.
- For Label, enter
Update Contact External ID and Phone
.
- For API Name, enter
Update_Contact_External_ID_and_Phone
.
- For How to Find Records to Update and Set Their Values, select Use the contact record that triggered the flow.
- Set Field Values:
- Field: External_Id__c, Value: Contact Point Email from Get_CP_Email > ssot__PartyId__c
- Field: Phone, Value: Contact Point Phone from Get_CP_Phone > ssot__FormattedE164PhoneNumber__c
- Field: External_Id__c, Value: Contact Point Email from Get_CP_Email > ssot__PartyId__c
- For Label, enter
- On the No path, add an Update Records element.
- For Label, enter
Update Contact External ID
.
- For API Name, enter
Update_Contact_External_ID
.
- For How to Find Records to Update and Set Their Values, select Use the contact record that triggered the flow.
- Set Field Values:
- Field: External_Id__c, Value: Contact Point Email from Get_CP_Email > ssot__PartyId__c
- Field: External_Id__c, Value: Contact Point Email from Get_CP_Email > ssot__PartyId__c
- For Label, enter
- Save the flow.
- For Flow Label, enter
New Contact - Update External ID and Phone
.
- For Flow Label, enter
- Click Activate to enable the flow.
Now when someone creates a contact, Salesforce automatically fills in that External ID field, saving your team time and effort! And with the External ID field consistently filled in, it’s easier to build flows that work with both sets of data. You build more flows that use this field in the next unit.