Table of Contents

Updating and creating bulk records to manage large amounts of data can be complicated. But what if I told you, you could do that without any code? Yes, Salesforce flow loops can make this possible. Adding the loop element will help you iterate over a collection of records, either from first to last or last to first.  

To better understand the Salesforce flow loop — its components, uses, record management, significant limitations, and how it is used — stay tuned. This blog will cover it all!

What is Salesforce Flow Loop element? 

A loop element in Salesforce Flow is an automated tool that lets users repeat a specific set of actions across similar records. It is a no-code element that helps users handle mass data operations like:

  • Lists of records retrieved using the Get records element. 
  • Collection of text or numeric data. 

Whether you want to update all 100 contacts or check the status for all 50 opportunities, the loop elements are your primary solution. However, multiple loop elements in Salesforce Flow primarily rely on three components. 

1. Collection Variable

The source data or the list of records that you want to process. It is typically populated by the Get records Elements and is added before the loop element is added in the flow. 

2. Loop Variable

The component extracts a single item from the collection variable during iteration. Any changes to this variable happen in the flow’s memory. It should be viewed and assigned in a new collection to avoid losing any changes. 

3. Direction (Iteration order)

As the name suggests, this component specifies the sequence of the loop process, which can be from first to last item or vice versa. However, the order does not matter for bulk updates. 

How to Implement Loops in Salesforce Flow?  

An essential element of Salesforce flow is bulkification, which is under the “Single SOQL, Single DML” pattern. 

Let’s understand with a simple scenario of a company that wants to update its account rating based on the annual revenue. If the account’s annual revenue is greater than 50 Lakhs, then we will set the rating of that account to Hot. Similarly, if the yearly revenue is ranging from 25 to 50 lakhs, we will put it for Warm, and if it is less than 25 Lakhs, the rating will be Cold.    

To implement this pattern in Salesforce Flow, you have to follow a 6-step implementation process:

1. Get the list

The first step is to get all the data/records that you intend to process. Use a Get Record element before the loop to gather this information into a single list. 

How to Implement Loops in Salesforce Flow image2
How to Implement Loops in Salesforce Flow image4

2. Prepare Blank Bucket

Once you receive the records, create an empty list or target collection to hold the records after modification. This empty list is isolated from the source data for the bulk updates.

How to Implement Loops in Salesforce Flow image5

3. Start the Loop

Command the loop element to start processing from step one by handling a single record at a time. 

How to Implement Loops in Salesforce Flow image9
How to Implement Loops in Salesforce Flow image8

4. Make Changes

Using the Assignment 1 element inside the loop to make changes in the fields. This step changes the records in the flow memory, not the database. 

How to Implement Loops in Salesforce Flow image3

5. Collect Changed Records

Again, use the second assignment element on the modified record in your blank bucket list from step 2. It brings the bulk list together, and you can check your update before the last step. 

How to Implement Loops in Salesforce Flow image6

6. Save Everything

Finally, after the loop is finished, execute Update record or create record element for the entire list from a blank bucket.

How to Implement Loops in Salesforce Flow image1

Now, we will understand how this record management process works: 

Updating records

Salesforce flow Loop update multiple records via a simple process of: 

  1. Preparation: Get all necessary information using the Get records element before the loop. 
  2. In-Loop Process: Modify temporary records (in-memory changes) using the Assignment element. 
  3. Collection: Add the changed Loop Variable to the dedicated target collection using the second Assignment element. 
  4. Execution: After the loop, execute a single Update Records element for the target collection to apply all changes in a single go. 

For better practice, one must avoid using update record operations under the loop. 

Creating records 

The Salesforce flow loop is also used to create new records in a few steps:  

  1. In-Loop Processing: Inside a loop, start a new single record handset and set the required field values. 
  2. Collection: Use the assignment element to add a new record to a dedicated collection. 
  3. Execution: After the loop, execute one Update Records element on the target collection to complete all changes in a single go. 

When a flow is created or updated, it needs to handle bulk records by placing SOQL once before the loop starts and adding DML after the loop finishes. If you do not work effectively with bulk features, you will reach the Salesforce flow limit and fail. 

Limitations of Salesforce Flow Loop

The Loop in Salesforce Flow has per-transaction limits, which can make it complicated. To avoid these, it is crucial to understand the few rules for each constraint:

ConstraintLimit (Max)Architectural Implication for Loop
SOQL Queries 100If you execute Get records more than 100 times in your transactions, the flow will fail instantly. 
DML Statements 150If you use Create, Update, or Delete more than 150 times, the flow will fail. Always use DML outside the loop.
DML Records Processed10,000The final saved or updated list cannot exceed 10,000 records. 
Maximum CPU Time10,000 millisecondsThe complex logic within a loop exhausts this time, leading to timeouts.
Executed Elements (Approx.)2,000Every step in the loop is counted. If your loop has 10 steps, you can only process 200 records. 

A violation of these limits can lead to an incomplete operation, no matter what path you choose. If your flow exceeds the limits, switch to Apex for robust, large-scale synchronisations. 

How to use Salesforce Flow Loops?

To better understand all this, below are a few Salesforce flow loop examples and case scenarios. 

Scenario: Bulk Updating Records

Here, the goal is to update the account status across all parents and related child records. To process this:

  1. Use the Get records element to get all child records. 
  2. Loop element to move through the records. 
  3. Assignment element to modify the record field in memory. 
  4. Again, use the assignment element to add the modified record. 
  5. Update the records in a single DML statement after the loop. 

For the above scenario, let’s take an example of Bulk update opportunities to closed won. 

  • First, get all target opportunities using a single Get Records element before the Loop.
  • Go through the records using the loop to change the StageName. 
  • Use the Assignment element to add them to a new collection. 
  • Finally, perform a single Update records action after the loop is completed. 

Final Thoughts

The Salesforce Flow loop element is an automated tool that simplifies creating or updating multiple records in bulk using the “Single SOQL, Single DML” pattern. Using this pattern, you can build efficient, scalable automation and handle high-volume data without limits. In the above blog, we learned a lot about flow loops —how they work, their uses, implementations, and limitations. To learn and discover a path to becoming a skilled Salesforce Flow Developer, start by exploring certifications and well-structured classes.

Latest Salesforce Insights

Book Free15-Minutes Career Counselling