How to update child records using salesforce flow

Updating related records is a common task in Salesforce, and it can be accomplished in many different ways. One way to achieve this is by using a flow, which is a powerful tool that allows you to automate processes and streamline workflows.

In this blog post, we will walk you through the process of updating child records using a loop element in Salesforce flow.

Problem Statement

If Account is marked as inactive i.e., Active as, “No”, then update all the related opportunity which is not equal to closed won or closed Lost stage, to Closed Lost stage.

Also read how to create a Data Table in salesforce Flow.

Step 1 : Create a Flow

The first step is to create a new flow. To do this, go to Setup > Flows > New Flow. Select “Record-Triggered Flow” as the type of flow.

Step 2 : Choose the Object and Trigger.

Next, choose the object as Account And choose the configure trigger as “A record is updated”. Then set the entry conditions as below,

  1. Active Field(Active__c) Equals as Value “No”.
  2. When to Run the Flow for Updated Records as,
    • Only when a record is updated to meet the condition requirements.
  3. Optimize the Flow for as,
    • Actions and Related Records.
  4. Then Click Done.

Step 3: Add the Get Record Element.

Add the Get record element to the canvas. And add the criteria to get all the related opportunities of account which is not equal to closed won or closed lost as stage name. So our flow condition should be as below.

  1. Object as Opportunity.
  2. Filter Opportunity Records : All Conditions Are Met(AND).
    • Choose Field AccountId Equals to Value as $Record>Account ID. [We need to update here only the Opportunity records which is belong to triggered account record , hence this condition is needed].
    • Choose StageName Equals to Value as Closed Won.
    • Choose StageName Equals to Value as Closed Lost.
  3. How Many Records to Store : Choose All records.
  4. How to Store Record Data : Automatically store all fields.
  5. Then Click Done.

Step 4: Check If the get records is Null?

I have added the decision element to check whether the value from get record element is null or not. So our condition should be as follows.

  1. Click the Plus icon to add the outcome.
  2. Add the label and API Name.
  3. Condition Requirements to Execute Outcome : All Conditions Are Met(AND).
  4. {!get_All_Opportnity_Records}[Step 3] is Null as value “False”.
  5. Then click Done.

Step 5: Loop Through all Opportunity Records.

In the loop element we will process through one by one records and we will update the stage name and all the processed records we will add in record collection variable using Assignment element.

In the Loop element choose collection variable as {!get_All_Opportnity_Records} [Step 3].

Step :6 Add assignment element to update stage Name & to add records to collection variable.

In this step we will add two assignment element. One to update the processed records from the Loop to stage as closed lost. And one more to add the records to the collection variable. So lets create first assignment element as per below.

Note : {!Loop_through_opportunity.StageName} is a variable in assignment record which is processed from loop.

Next, we will add the records to collection variable. Before that lets create an collection variable as per below image.

Then, will add the records to collection variable using another assignment element, as per below.

Step 7 : Update the records.

The Update Records element allows you to update one or more records at the same time. To use this element to update the related records, you need to specify the record or records you want to update and the fields you want to update. So in our case we will choose the record collection variable to update.

  1. How to Find Records to Update and Set Their Values, as
    • Choose Use the IDs and all field values from a record or record collection.
  2. Select Record(s) to Update as,
    • {!updatedOpportuityRecords} [Step 6]
  3. Then Click Done.

Step 8 : Save the Flow

Add the label and API name of flow and Save.


Updating related records using a flow is a powerful tool that can save you time and effort. By following the steps outlined in this blog post, you can create a flow that updates related records in your Salesforce organization with ease.

If you were not followed our previous blog, then read it here.

Also Read

Sharing Is Caring:

4 thoughts on “How to update child records using salesforce flow”

  1. In the second part of step 6, where you add the value to the record collection variable, can you please show the full value of the Current Item from Loop? I’m working on a similar


Leave a Comment