Jennifer Lee and Stephen Spencer in a new episode of "Automate This!'.

Automate This! — Update Related Records with Flow

By

Welcome to another “Automate This!” In this live-streamed video series, we cover all things automation, from use cases and best practices to showcasing solutions built by #AwesomeAdmin Trailblazers like you. Automation helps you remove manual tasks, drive efficiency, and eliminate friction and redundancy. In this episode, see how Stephen Spencer uses loops in a record-triggered flow to automate his business process to update related records.


Business use case

Our customer support reps spend their days updating dozens of records. One of the things that they must do is update the Division field on open opportunities if the owner of the account or segment is changing. In order to simplify the task, we want to automate the process of updating the Division field on the related open opportunities to ensure that this would happen and to protect the quality of the data in our system.

Solution: Record-triggered flow

To solve this problem, I created a record-triggered flow that will launch whenever an account record is changed to match the entry criteria that I will add later on in the process. 

The completed flow

Record-triggered flows are one of the core Salesforce flows that you can use to automate your business processes.

The new flow with record-triggered flow selected

You can trigger a record-triggered flow before or after the record is saved to the database. Updating the record before the save gives you the ability to update the record that triggered the process prior to them being saved. This is a lot faster since the record is only saving once, therefore only going through the assignment rules, workflow rules, auto-response rules, and other things once instead of twice. This functionality could be used as a substitute for a trigger depending on the scenario and business requirements.

Record-triggered flows can be launched in the following ways:

  • A record is created.
  • A record is updated.
  • A record is created or updated.
  • A record is deleted.

Let’s create the flow

Start

After I selected the flow type of record-triggered, I configured the setup to trigger my record-triggered flow.

The Start element

I set the object for which I want the flow to trigger—Account. I want my process to trigger when a record is created or updated.

Configured Start element of the record-triggered flow

I then set the Entry Criteria to instruct the flow when it needs to run. In this scenario, I set the conditions to run when the owner is changed or the segment is “Canada” and organization type is changed.

  • OwnerId Is Changed True
  • Segment__c Equals Canada
  • Organization_Type__c is Changed True

Configured entry conditions for the record-triggered flow

Get Record

I now need to find all the open opportunities associated to the account. To do this, I use the Get Records element so that I can define which records I want to pull in.

Adding the Get Records flow element to the record-triggered flow

I set the object for the records that I would like returned—Opportunity—and set the filter criteria to return all open opportunities that also have the same account as the record that triggered the flow to start. I name this element “Get Open Opportunities.”

Condition Requirements:

  • AccountId Equals $Record>Account ID (Note: Use $Record to use any attributes of the record that triggered the flow.)
  • IsClosed Equals False

Configured Get Records flow element

Decision

I need to determine the record’s segment to later update the division. I used the Decision element to do this.

Decision element used in the flow

I created outcomes by giving the outcome a name and defining what field values define each outcome. For example, in the Sport - Outdoor outcome, a record would follow this path if the record’s segment equals “College Athletics,” “NFL,” or “Stadium & Outdoor Sports.” Note: I used the $Record variable to reference the Segment field associated to it.

Configured Decision flow element

Loop

I use the Loop flow element because I need to loop through the open Opportunity records. I reference the variable name “Get_Open_Opportunities” that I created earlier using the Get Records flow element and set it to run through the records from “First item to last item”.

Configured Loop flow element

In my next step, I need to assign a value to the Division field of the current item in the loop. Here, I use the Assignment flow element to set the Division field to a specific value. In this example, we’ll set the field to “Arts” by assigning it to the {!Loop_Through_Arts.Division__c} which is the variable for the current record in the loop.

Configured Assignment flow element that sets the division to ‘Arts’

I need to add the loop record to a collection of open opportunity records that I will update at the end of the loop. Note: It’s bad practice to make updates to records within the loop.

I added another Assignment element to add the current item in the loop to a collection variable. I created the collection variable by selecting the Manager tab in the toolbox and clicking the New Resource button. I then set the Resource Type to “Variable” and selected the data type of record since I will be storing records. I selected the Allow multiple values (collection) checkbox so that I can hold multiple records in one collection variable. I set the object to Opportunity since these were open opportunities that I will hold in the collection variable.

Configured OppsCollectionVar collection variable

Note: A variable is a placeholder for a value that you don’t know yet. A collection variable is used to hold more than one value.

OppsCollectionVar Add Current Item from Loop_Loops_Through_Arts

The configured Assignment element

I need to create a loop and two Assignment flow elements for each decision outcome. However, I’m not going to create a new loop and two Assignment elements for each outcome. Rather, I’m going to use the lasso to select the loop and two Assignment flow elements, select the copy button, tweak the elements to each decision outcome, and connect each loop-Assignment combination to each decision outcome.

Update

After I’ve repeated the loop steps for all of the outcomes in my Decision element, I want to update the Division field for all of the open opportunity records in my collection variable OppsCollectionVar using the Update Records flow element.

Configured Update Records flow element

Test the flow

Now that the flow has been completed in a sandbox, I use the Debug button to test it to make sure that it runs properly and that it doesn’t alter any records that shouldn’t be touched.

Once the flow has passed my testing, it’s ready to be tested by the business so that they can approve my automation prior to my moving it into the production environment.

The Debug feature

Have a use case for automatically updating records related to the record that triggered the automation? Give Flow a try! Create a flow that uses a Get Records to find the related records, a loop and two Assignments to work through the queried records, and an Update Records outside the loop to update the related records.

Resources

 

Want to see more good stuff? Subscribe to our channel!

SUBSCRIBE TODAY
Boost your study routine with flows and email-to-text gateways

Boost Your Salesforce Certification Study Routine with Flows & Email-to-Text Gateways | Automate This!

Welcome to another “Automate This!” In this live-streamed video series, we cover all things automation, from use cases and best practices to showcasing solutions built by Awesome Admin Trailblazers like you. With automation, you can remove manual tasks, drive efficiency, and eliminate friction and redundancy. In this episode, let’s see how Bradley Condon built the […]

READ MORE
Leverage flows to process inbound emails with documents

Leverage Flows To Process Inbound Emails With Documents | Automate This!

Welcome to another “Automate This!” In this live-streamed video series, we cover all things automation, from use cases and best practices to showcasing solutions built by Awesome Admin Trailblazers like you. With automation, you can remove manual tasks, drive efficiency, and eliminate friction and redundancy. In this episode, let’s see how Ohad Idan vanquishes shared […]

READ MORE
Improve sales funnel velocity with Flow

Improve Sales Funnel Velocity Using Flow | Automate This!

Welcome to another “Automate This!” In this live-streamed video series, we cover all things automation, from use cases and best practices to showcasing solutions built by Awesome Admin Trailblazers like you. With automation, you can remove manual tasks, drive efficiency, and eliminate friction and redundancy. In this episode, learn how Becka Dente leverages a simple […]

READ MORE