Salesforce Flow is one of the most powerful features used by admins and developers to automate business processes without writing code.
It allows you to create logic-based automation that updates records, sends emails, creates tasks, and performs many other actions.
One of the most important elements in Flow is the Loop Element. When working with multiple records, you often need to perform the same action repeatedly.
Instead of writing repetitive logic, the Loop element lets you process each record in a structured, one-by-one manner.
I was developing a Salesforce Flow that automatically sets all related tasks to “Completed” when a case is closed.
For example, when a support agent closes a case, there may still be open tasks related to it, such as follow-up calls or reminders.
We want to automatically mark these tasks as “Completed” so that the agent does not need to update each task individually.
To achieve this, I used the loop element in Salesforce Flow to process each related Task and update its status efficiently.
In this article, I will explain the loop element in Salesforce Flow. I will explain what a loop element is, when it can be used, and provide a real-time scenario with a step-by-step explanation.
What is a Loop Element in Salesforce Flow?
When we fetch records from a Salesforce object using the ‘get records’ element or record variable, and store them as a collection.
if we need to perform any operation on those records, a Loop element iterates through the collection of records (like a list) and performs actions on each item one by one.
The Loop Element in Salesforce Flow iterates over a collection of records and performs actions on each record individually.
In simple words, when you have multiple records (like a list), and you want to do the same operation on each record, you use a Loop.
For example:
- Update multiple records
- Send emails to multiple contacts
- Create records for each item
- Check conditions for each record
Technically, the Loop processes one record at a time from a collection variable and allows you to perform actions on it.
Why Do We Use the Loop Element?
We can use the loop element when we need to do the same task on each record in a list, one at a time, inside our flow.
Below, I have given some common examples so that you can easily understand where we can use the loop element in the flow:
- Update a field on each record in a list.
- Send an email to each contact in a List collection.
- Create related records for each item in a list.
- Check conditions and take action on each record separately.
In simple terms, we use a loop element whenever we need to handle each record in our collection step by step in our Flow.
When building flows, you often deal with multiple records. Without loops, you would need to write separate logic for each record, which is not practical.
Loop helps to:
- Save time
- Reduce complexity
- Handle bulk records efficiently
- Avoid repetitive logic
Example scenario:
If a Case is closed, you want to update all related Tasks to “Completed”. Instead of updating each task manually, you can use a Loop to process all tasks automatically.
How Loop Element Works in Salesforce Flow
The Loop Element works with three main components:
- Collection Variable: This is the list of records you want to loop through.
- Example:
- List of Tasks
- List of Contacts
- Example:
- Loop Variable (Current Item): During each iteration, Flow stores one record temporarily in a variable called:
- “Current Item from Loop”
- Direction – You can choose:
- First item to last item
- Last item to first item
- Flow Execution Logic
- Get Records → fetch multiple records
- Loop → iterate through each record
- Assignment → modify data
- Store in collection
- Update/Create records
Use Loop Element in Salesforce Flow
Now, let’s understand how to use the loop element in Salesforce Flow to iterate over records that we have in the Get Record element or a Collection Variable.
Example: Use Loop to Update Record in Salesforce Flow
Below, I will explain when we need to set all related tasks to “Completed” when a Case is closed.
Here we need to go through all the case-related task records to update their status.
Click on the Setup. -> Home Page. -> In the Quick Find Box, Search for Flows. You will see an option under Process Automation. -> Click on Flows.
Click on the New Flow button to create a new flow. Select the Record Trigger Flow. Then, click on the Create button.
In the start element, we have to select the triggering object. In our scenario, the Case is a triggering object because when the case status is updated to ‘closed’, the associated task is marked as completed.
Therefore, in the Configure Trigger, select ‘A record is updated’.
I also added one condition: the Status Equals Closed. Then, I selected “Actions and Related Records” in the “Optimize the Flow” option.

First, we need to retrieve all the tasks stored in the Task object. For that, we need to add the Get Records element and enter a Label and API Name.
In the Object field, select the Task object to fetch the task-related information. Then, we need to retrieve only the tasks related to the case that are not marked as completed.
Therefore, we need to add filter records and provide the corresponding condition. In How many records to store, we need to store all the records.

Now, we will use the loop element to iterate over the records retrieved by the get record element. To add the Loop Element, click on the Add Element icon.
Then, enter the element Label and API Name.
Then, select the Collection Variable from Get Records(API Name) and select the iteration direction from the first item to the last item.

To store the updated task records, we need to create a new variable. To do that, click New Resource and select the Resource Type as Variable. Enter API Name. Here, I have entered TaskToUpdate.
Select ‘Data Type’ as ‘Record‘ and allow multiple values, and select ‘Task‘ as the object. Click on Done.

In this step, we will assign the ‘Completed’ value to the status field from the loop element. To do so, add the Assignment Element. Then, enter the element Label and API Name.
Again, we need to store the assigned value records in the variable that we created so that we can update all tasks simultaneously.
Here in the Set variable Values, I added two conditions as follows:
- Loop>Task>Status = ‘Completed’: Here, we assigned the Completed value to the status field from the task object.
- TaskToUpdate -> Add -> Loop: Here we store the assigned records in the created collection variable so that we can update them simultaneously.

After closing the case, we set the task status to ‘Completed,’ but we hadn’t updated it in the object yet.
We need to update the record to see the changes in the task object. To do this, add the Update Record element and provide a Label and API Name.
Next, select ‘Use the IDs and all field values from a record or collection.‘ So we can add the collection variable that stores all the changed status records.
Then we need to provide the variable. Here we created TaskToUpdate.

Now we are ready to save the flow. For that, click the Save button, provide the flow Label, and the API Name will be automatically populated.
After that, always debug the flow before activating it to ensure that the working flow is correct and that there are no runtime errors. Then activate the flow.

Proof of Concept:
After activating the flow, navigate to the Case tab to update the case status to closed record. Before that, let’s see the task related to this open case.

To view the related task, navigate to the Related tab in the case object, where you will find all related tasks. Open the task, and you will see different task statuses.

Now navigate to the case again, change the case status to ‘Closed‘, and save the changes.

Now, as you navigate to the related task of the closed case, you will see that the status of that task is also set to Completed automatically.

In this way, we can use the Loop element to update each record in the Salesforce Flow collection individually.
Example: Use a Loop to Create a Record in Salesforce Flow
I was building a Flow for a real estate company that wanted to automatically create follow-up Tasks for each buyer who showed interest when a Property is marked as “Sold.”
For example, when any property is sold, there may be multiple interested buyers, but they don’t get it. The sales team wants to follow up with these buyers to offer other similar properties.
Before starting to create the flow, here are some prerequisites:
- I have created Custom Objects named ‘Property’ and ‘Interested Buyer‘.
- The interested buyer has a lookup relationship to the property, allowing them to track which property they are interested in.
Create Record Trigger Flow. At the Start element, provide the details as follows:
- Object: Property.
- Configure Trigger: A record is updated.
- Entry Condition: When the Status is set to ‘Sold’.
- Optimize the Flow: Actions and Related Records.

- Next, add the ‘Get Record‘ element and retrieve all the records of interested buyers related to the property.
- Store all records. We want to create a task for each interested buyer who wishes to purchase the property.
- After that, add a Loop Element to iterate over all related buyers, creating a task for each. The sales team can then suggest similar properties or provide any other relevant suggestions.
- Here, we need to provide the Collection Variable. We have added a ‘get record‘ element with all records, so in this case, we need to provide that element.
Now we need to create the Record Variable so that we can assign values to the task that we will create for interested buyers (NewTask).
Using this record variable, we can access the task object fields and assign values to them.

After creating a record variable again, we need to create a Record Collection Variable to store the task that will be created (TaskToUpdate).
Then we can pass that variable to create a record element, so that any task in that variable will be created simultaneously.
Add an Assignment element to assign causes to the record variable, and also, we need to add that record variable to the record collection variable.

After adding all new tasks to the record collection variable, we need to add the Create Record Element.
As we are going to create multiple records in ‘How Many Records to Create‘, we need to select ‘Multiple‘.
In the Record Collection, we need to provide the Record Collection Variable we created, as we have stored all new tasks in that assignment element.

After that, save the flow, Debut it, and then activate it.
Proof of Concept:
In the image below, you can see two interested buyers who want to buy the same property, and they don’t have any open tasks yet.

I have now opened the property record that the above interested buyers wish to purchase. Then, I changed the status of this property from ‘Available‘ to ‘Sold‘.
Now, as per our scenario, since this property is not available for the above users, we need to create a task for those users to suggest similar properties or follow up with them.

You can see that after changing the property status, the task has been assigned to the interested buyers, as per the values we assigned to the task fields using the assignment element in Flow.

In this way, we can use the loop element to create a related record for each apparent record individually from the Salesforce Flow collection.
Loop vs Other Flow Elements in Salesforce
| Feature | Loop Element | Get Records | Assignment | Decision |
|---|---|---|---|---|
| Purpose | Iterate records | Fetch data | Modify data | Apply conditions |
| Works on multiple records | Yes | Yes | No | No |
| Used for automation | Yes | Yes | Yes | Yes |
Frequently Asked Questions
What is Loop in Salesforce Flow?
A loop is used to iterate over multiple records and perform actions on each.
Why do we use Loop?
We use Loop when we want to perform the same action on multiple records.
Can we update records inside Loop?
No, it is not recommended. Always update records after the loop.
What is a Collection Variable?
A collection variable is a group of records used in Flow.
What happens if we don’t use Loop?
You cannot efficiently process multiple records.
Conclusion
The Loop Element in Salesforce Flow is a powerful feature that helps you easily automate repetitive tasks. It allows you to process multiple records efficiently without writing code.
By understanding how Loop works and following best practices, you can build optimized and scalable flows. Always remember to use collection variables, avoid updating records inside the loop, and structure your flow properly.
I hope you have an idea about the loop element in Salesforce Flow. I have explained what a loop element is, when it can be used, and provided a real-time scenario with a step-by-step explanation.
You may like to read:
- Wait Element in Salesforce Flow
- Transform Element in Salesforce Flow
- Decision Element in Salesforce Flow
- Call Approval Process From Salesforce Flow
I am Bijay Kumar, the founder of SalesforceFAQs.com. Having over 10 years of experience working in salesforce technologies for clients across the world (Canada, Australia, United States, United Kingdom, New Zealand, etc.). I am a certified salesforce administrator and expert with experience in developing salesforce applications and projects. My goal is to make it easy for people to learn and use salesforce technologies by providing simple and easy-to-understand solutions. Check out the complete profile on About us.