Welcome back to our Salesforce Flow series!
Requirement
We need to ensure that whenever an account's phone number is updated, all contacts linked to that account have their phone numbers updated to match the new account phone number.
Steps to Create the Flow
Let's break down the steps to create this flow:
Create a Record-Triggered Flow
Configure Entry Conditions
Fetch Related Contacts
Loop Through Contacts
Update Contact Records
Step-by-Step Guide
1. Create a Record-Triggered Flow
First, we need to create a new flow that triggers when a record is updated.
Navigate to Setup.
In the Quick Find box, type Flows, and select Flows.
Click New Flow.
Select Record-Triggered Flow and click Create.
2. Configure Entry Conditions
Next, we need to specify the conditions that trigger this flow.
In the Configure Start screen, select Object as Account.
Set the Trigger to A record is updated.
Under Entry Conditions, select Conditions are met.
Add a condition: Phone Is Changed Equals True.
Ensure the Condition Requirements are set to All Conditions Are Met (AND).
Click Done.
3. Fetch Related Contacts
We now need to fetch all contacts associated with the account whose phone number was updated.
Click the + icon and select Get Records.
Label this element as Get Contacts.
In the Object field, select Contact.
Set the Filter Contact Records conditions to:
AccountId Equals {!$Record.Id}
Store all records in a variable, and ensure Automatically store all fields is selected.
Click Done.
4. Loop Through Contacts
To update each contact’s phone number, we’ll use a loop.
Click the + icon and select Loop.
Select the Collection Variable containing the contacts fetched by the previous element.
Choose to Iterate Through the collection.
Click Done.
Within this loop, we’ll set the contact phone number to the account phone number.
Inside the loop, click the + icon and select Assignment.
Label this element as Set Contact Phone Number.
Assign the contact phone number to the account phone number.
Create a collection and add the current loop record to the collection after assigning the phone number to the contact.
Click Done.
5. Update Contact Records
Finally, we’ll update all contact records outside of the loop.
Click the + icon and select Update Records.
Label this element as Update Contacts.
Set the How to Find Records to Update to Use the IDs and all field values from a record or record collection.
Select the collection variable containing the contacts to update.
Click Done.
Conclusion
Your flow should now be complete and look something like this:
Start (Triggered when an Account record is updated and the phone number has changed)
Get Contacts (Fetch all contacts related to the account)
Loop Through Contacts (Iterate through each contact)
Set Contact Phone Number (Assign the new phone number to each contact)
Add Contacts to Collection (Prepare contacts for bulk update)
Update Contacts (Update all contact records with the new phone number)
Activate your flow and test it by updating an account’s phone number. You should see the phone numbers of all associated contacts update automatically.
That’s it for today’s guide on updating records using Salesforce Flow. Stay tuned for more insights and tutorials in our Salesforce Flow series!