By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
horizontal-light horizontal-dark
  • Home
  • Tutorials
    • Salesforce AI
    • Salesforce DevOps
    • Career
    • Errors
    • Interview Questions
    • Salesforce Integration
    • Salesforce Flow
  • Salesforce Tools
  • Apex Development
  • Lightning Web Components
  • Salesforce Admin
  • About
    • Privacy Policy
    • Disclaimer
    • Terms & Conditions
    • Contact
SalesforceCornerSalesforceCorner
Search
  • Home
  • Tutorials
    • Salesforce AI
    • Salesforce DevOps
    • Career
    • Errors
    • Interview Questions
    • Salesforce Integration
    • Salesforce Flow
  • Salesforce Tools
  • Apex Development
  • Lightning Web Components
  • Salesforce Admin
  • About
    • Privacy Policy
    • Disclaimer
    • Terms & Conditions
    • Contact
Follow US
Salesforce Corner » Salesforce Flow » Salesforce Flow Loops: Collections, Iteration, and Best Practices
Salesforce Flow

Salesforce Flow Loops: Collections, Iteration, and Best Practices

Build Efficient Salesforce Flows with Smart Loop Logic

Neha Panwar
By
Neha Panwar
ByNeha Panwar
Salesforce Developer and Technical Writer
Neha Panwar is a Salesforce developer and technical writer who shares practical tutorials, Apex guides, and real-world solutions for developers. She focuses on simplifying Salesforce concepts,...
Follow:
- Salesforce Developer and Technical Writer
Last updated: 2026/07/01
Share
Salesforce Flow Loops tutorial diagram
SHARE

Salesforce Flow has become the preferred automation tool for many admins because it can handle complex business processes without writing Apex code. As your flows become more advanced, you’ll often need to process multiple records instead of just one. That’s where Salesforce Flow Loops become essential.

A Loop allows a Flow to process each record in a collection individually. Whether you’re updating hundreds of Contacts, creating Tasks for multiple Opportunities, or validating records one by one, loops make automation scalable and easier to manage.

However, loops are also one of the most common reasons for slow flows and governor limit errors. Many beginners place Update Records or Create Records elements inside a loop, which quickly causes performance issues.

In this guide, you’ll learn how Salesforce Flow Loops work, how collection variables are used, practical examples, common mistakes, and the best practices every Salesforce Admin should follow.

Contents
What Is a Salesforce Flow Loop?When Should You Use a Loop?Understanding Collection VariablesLoop Variable ExplainedHow Salesforce Flow Processes a LoopImage Prompt (Place Here)Building Your First LoopNever Perform DML Inside a LoopWhy Create Another Collection?Common Mistakes with Flow LoopsCan You Avoid Using a Loop?Loop vs Update Records vs TransformPerformance Tips for Salesforce Flow LoopsGet Only the Records You NeedAvoid Nested LoopsKeep Assignment Logic SimplePerform One Bulk UpdateReal Business ScenarioCollections and AssignmentsCommon Errors to AvoidBest Practices ChecklistFrequently Asked QuestionsWhat is a Loop in Salesforce Flow?What is a Collection Variable?Why shouldn’t I use Update Records inside a Loop?Can I create records inside a Loop?When should I use Transform instead of a Loop?Final ThoughtsRelated Articles

What Is a Salesforce Flow Loop?

A Loop is a Logic element in Flow Builder that processes every record inside a collection one at a time.

Instead of updating records manually, Salesforce automatically picks one record from the collection, processes it, then moves to the next record until every record has been handled.

Think of it like reading every page in a book.

Instead of opening every page individually, you simply keep turning pages until you reach the end.

Flows work in exactly the same way.

When Should You Use a Loop?

Loops are useful whenever your Flow needs to work with multiple records.

Common examples include:

  • Updating all Contacts related to an Account
  • Creating Tasks for multiple Opportunities
  • Sending notifications to every Case Owner
  • Checking each Product before creating Opportunity Line Items
  • Updating custom object records in bulk
  • Filtering records based on conditions

If your Flow only processes one record, you usually don’t need a Loop.

Salesforce Flow Builder loop example
Salesforce Flow Builder loop example

Understanding Collection Variables

Before using a Loop, you need a Collection Variable.

A Collection Variable stores multiple records of the same object.

For example:

Suppose your Get Records element retrieves every Contact related to an Account.

Instead of storing one Contact, Salesforce stores every Contact inside a collection.

Example:

Contact A
Contact B
Contact C
Contact D
Contact E

The Loop processes these records one after another.

Without a collection, a Loop cannot run.

Loop Variable Explained

While a Collection contains multiple records, the Loop Variable contains only one record at a time.

Imagine you have 500 Contacts.

During execution:

Iteration 1

Current Contact = Contact A

Iteration 2

Current Contact = Contact B

Iteration 3

Current Contact = Contact C

The Loop Variable keeps changing until every record has been processed.

This temporary variable is what Assignment elements modify during each iteration.

How Salesforce Flow Processes a Loop

The execution sequence is simple.

  1. Get Records retrieves multiple records.
  2. Records are stored inside a Collection Variable.
  3. Loop picks the first record.
  4. Assignment updates the current record.
  5. Updated record is added to another collection.
  6. Loop repeats until every record is processed.
  7. Update Records runs once after the Loop finishes.

This approach keeps your Flow bulk-safe and avoids governor limits.

Image Prompt (Place Here)

.

Building Your First Loop

Let’s understand a practical business example.

Suppose every Account has an Active checkbox.

Whenever an Account becomes active, all related Contacts should also become active automatically.

The Flow would look like this:

Start

↓

Get Records (All Contacts)

↓

Loop

↓

Assignment

↓

Add Contact to Update Collection

↓

Update Records

Notice something important.

There is no Update Records element inside the Loop.

Instead, every modified Contact is stored inside another collection.

Only after the Loop finishes does Salesforce perform one bulk update.

This is exactly how Apex developers bulkify code, and Flow follows the same principle. If you’re interested in understanding why Salesforce recommends bulk processing, How to Prevent Recursive Triggers in Salesforce Apex explains similar concepts from the Apex side.

Never Perform DML Inside a Loop

This is the number one Flow best practice.

Many beginners do this:

Loop

↓

Update Records

↓

Next Record

↓

Update Records

↓

Next Record

If your Account has 500 Contacts, Salesforce executes 500 separate updates.

This wastes resources and can easily hit governor limits.

Instead:

Loop

↓

Assignment

↓

Store Updated Record

↓

Loop Ends

↓

Single Update Records Element

One DML operation is always faster than hundreds of individual updates.

Why Create Another Collection?

A common question is:

“Why not update the original collection?”

Technically, you could modify the Loop Variable, but Salesforce best practice is to create a separate collection for updated records.

Benefits include:

  • Easier debugging
  • Cleaner Flow design
  • Better readability
  • Safer maintenance
  • Bulk update support

Keeping the original collection unchanged also reduces accidental errors during future modifications.

Common Mistakes with Flow Loops

Many admins make the same mistakes while learning Flow.

Some of the most common include:

  • Using Create Records inside a Loop
  • Using Update Records inside every iteration
  • Forgetting to add modified records into an update collection
  • Looping through records when a single Update Records element can do the job
  • Creating unnecessary nested loops

As your automations grow, keeping Flow logic simple becomes increasingly important. How to Use Decision Elements and Branching in Salesforce Flow is another useful guide for reducing unnecessary complexity before introducing loops.

Can You Avoid Using a Loop?

One question many Salesforce Admins ask is whether every collection requires a Loop.

The answer is no.

In some situations, Salesforce provides more efficient elements that eliminate the need for iteration altogether.

For example, if you simply want to update every Contact related to an Account with the same value, the Update Records element can perform the entire operation without using a Loop.

Similarly, if you’re mapping one collection to another, the Transform element is often a better choice.

Loops should be used only when each record requires individual processing or decision-making.

Loop vs Update Records vs Transform

Understanding when to use each element can make your Flow much faster and easier to maintain.

RequirementBest Choice
Update all matching records with the same valueUpdate Records
Process every record individuallyLoop
Convert one collection into anotherTransform
Perform calculations on each recordLoop
Build a new collectionLoop + Assignment

Choosing the correct element keeps your automation simple and reduces execution time.

Performance Tips for Salesforce Flow Loops

As the number of records increases, Flow performance becomes more important.

Follow these recommendations when building production-ready Flows.

Get Only the Records You Need

Avoid retrieving unnecessary records.

Instead of getting every Contact in your org, filter only the Contacts that actually need processing.

Smaller collections result in faster Flow execution.

Avoid Nested Loops

A Loop inside another Loop increases execution time dramatically.

If one Loop processes 100 records and another processes 100 records inside it, Salesforce performs 10,000 iterations.

Whenever possible, redesign the automation to use a single Loop.

Keep Assignment Logic Simple

Assignments should only update fields or prepare records for later processing.

Avoid placing unnecessary Decisions or Actions inside every iteration unless they’re required.

Perform One Bulk Update

Collect every modified record into an update collection.

Run a single Update Records element after the Loop completes.

This approach follows Salesforce bulk processing best practices and significantly reduces governor limit consumption.

Salesforce Flow Builder interface in action
Salesforce Flow Builder interface in action

Real Business Scenario

Imagine your company stores an Active Customer checkbox on the Account object.

Whenever that checkbox changes, every related Contact should automatically receive the same value.

A good Flow would work like this:

  1. Account is updated.
  2. Get all related Contacts.
  3. Loop through each Contact.
  4. Update the Active field using an Assignment.
  5. Add the Contact to an update collection.
  6. Update every Contact together after the Loop finishes.

This design is scalable, easy to understand, and works efficiently even when an Account has hundreds of Contacts.

Collections and Assignments

Loops become much more powerful when combined with Assignment elements.

Inside a Loop you can:

  • Update field values.
  • Build a new collection.
  • Store filtered records.
  • Calculate totals.
  • Create text collections.
  • Prepare records for Create or Update operations.

Think of the Assignment element as the place where your business logic actually happens.

The Loop simply controls the iteration.

Common Errors to Avoid

Even experienced admins occasionally make mistakes when working with Loops.

Watch out for these common issues:

  • Forgetting to select All Records in the Get Records element.
  • Updating records directly inside the Loop.
  • Reusing the original collection instead of creating an update collection.
  • Using nested Loops unnecessarily.
  • Looping through thousands of records when a Transform or Update Records element would work better.
  • Adding unnecessary Decision elements inside every iteration.

Keeping your Flow clean makes debugging much easier later.

Salesforce Flow Builder debug results
Salesforce Flow Builder debug results

Best Practices Checklist

Before activating a Flow that contains Loops, verify the following:

  • Use Get Records to retrieve only required records.
  • Store records in a Collection Variable.
  • Process records using a Loop.
  • Modify records with Assignment elements.
  • Add modified records to a separate collection.
  • Perform one Create Records or Update Records operation after the Loop.
  • Test with large data volumes before deployment.
  • Avoid nested Loops whenever possible.

Following these practices improves performance and keeps your Flow compliant with Salesforce governor limits.

Frequently Asked Questions

What is a Loop in Salesforce Flow?

A Loop is a Flow element that processes each record in a collection one at a time. It’s commonly used to update, evaluate, or prepare multiple records before performing a bulk operation.

What is a Collection Variable?

A Collection Variable stores multiple records or values of the same type. Loop elements require a collection as their input.

Why shouldn’t I use Update Records inside a Loop?

Updating records during every iteration creates multiple DML operations, which can impact performance and exceed Salesforce governor limits. It’s better to collect all modified records and update them once after the Loop ends.

Can I create records inside a Loop?

Technically yes, but it’s not recommended for large collections. Store records in a collection first and perform one bulk Create Records operation after the Loop whenever possible.

When should I use Transform instead of a Loop?

Use the Transform element when you need to map one collection into another without applying record-by-record business logic. It’s often simpler and more efficient than a Loop.

Final Thoughts

Salesforce Flow Loops are one of the most valuable tools for building scalable automation. They allow you to process collections efficiently, apply business logic to individual records, and prepare data for bulk operations.

The biggest takeaway is simple: never perform DML inside a Loop. Instead, use Assignment elements to build a new collection and execute a single Create or Update operation after the Loop completes. This design improves performance, reduces governor limit issues, and makes your automation easier to maintain as your Salesforce org grows.

Related Articles

Continue learning Salesforce Flow with these guides:

  • Apex Switch Statements vs If-Else: When and How to Use Each
  • Salesforce Sandbox Types Explained: Developer, Developer Pro, Partial Copy, and Full
  • How to Prevent Recursive Triggers in Salesforce Apex
  • WhoId vs WhatId in Salesforce: What’s the Difference and When Should You Use Each?
  • Salesforce Field History Tracking vs Setup Audit Trail: Which to Use?

TAGGED:AutomationCollection VariablesFlow Best PracticesFlow BuilderLoop Elementsalesforce adminsalesforce automationsalesforce developersalesforce flowSalesforce Tutorials
Share This Article
Facebook Email Print
ByNeha Panwar
Salesforce Developer and Technical Writer
Follow:
Neha Panwar is a Salesforce developer and technical writer who shares practical tutorials, Apex guides, and real-world solutions for developers. She focuses on simplifying Salesforce concepts, integrations, and backend development to help beginners and professionals learn faster.
Leave a Comment Leave a Comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Latest Post

Salesforce dynamic forms interface illustration
Salesforce Dynamic Forms: A Better Way to Show and Hide Fields
Salesforce Flow
Salesforce flow debugging guide
How to Debug and Fix Salesforce Flow Errors ?
Salesforce Flow
WhoId vs WhatId in Salesforce
WhoId vs WhatId in Salesforce: What’s the Difference and When Should You Use Each?
Apex Development
Salesforce Apex string methods tutorial
20 Apex String Methods Every Salesforce Developer Should Know
Apex Development
How to prevent recursive triggers
How to Prevent Recursive Triggers in Salesforce Apex
Apex Development

Stay Updated with Salesforce Tutorials

Get the latest Salesforce guides, tutorials, and developer tips delivered to your inbox.
slaesforce corner mascot

Explore More Topics

  • salesforce admin
  • salesforce developer
  • Salesforce Admin
  • salesforce apex
  • Salesforce Development
  • salesforce tutorial
  • salesforce security
  • salesforce automation
  • Apex Development
  • lightning web components
  • Lightning Web Components
  • salesforce lwc
  • Salesforce Tutorials
  • Salesforce Tools
  • lwc tutorial
horizontal-dark-transparent

Learn Salesforce development with practical tutorials, Apex guides, integration examples, and real-world solutions for developers.

  • Quick Links:
  • About
  • Contact
  • Privacy Policy
  • Disclaimer
  • Terms & Conditions
Facebook Twitter Youtube Linkedin-in

Salesforce Corner © 2026

Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?