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). 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 Resortsโ 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 Resortsโ 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 Resortsโ 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.
- Under Frequently Used, select Record-Triggered Flow.
- 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 False.
- For Field, select Email.
- Click Add Condition.
- In the second condition requirement:
- For Field, select External Id.
- For Operator, select Is Null.
- For Value, select True.
- For Field, select External Id.
- 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.
- Enable the Add Asynchronous Path toggle.
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 Email Address.
- For Operator, select Equals.
- For Value, select Triggering Contact, then select Email.
- For Field, select Email Address.
- Click Add Condition and set these values in the second condition requirement:
- For Field, select Data Source Object.
- 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 Data Source Object.
- 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 Party.
- For Operator, select Equals.
- For Value, select Contact Point Email from Get CP Email, then select Party.
- For Field, select Party.
- 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, Value: Contact Point Email from Get CP Email > Party
- Field: Business Phone, Value: Contact Point Phone from Get CP Phone > Formatted E164 Phone Number
- Field: External Id, Value: Contact Point Email from Get CP Email > Party
- 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, Value: Contact Point Email from Get CP Email > Party
- Field: External Id, Value: Contact Point Email from Get CP Email > Party
- 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.