Flow Loops and Collections are essential components in Salesforce Flow Builder that enable administrators to process multiple records efficiently. Collections are variables that store multiple values or records of the same data type, similar to a list or array. There are three main types of collect…Flow Loops and Collections are essential components in Salesforce Flow Builder that enable administrators to process multiple records efficiently. Collections are variables that store multiple values or records of the same data type, similar to a list or array. There are three main types of collections in Flow: Record Collections (storing multiple Salesforce records), Text Collections (storing multiple text values), and Number Collections (storing multiple numeric values). Collections are populated through Get Records elements, which query the database and return matching records into a collection variable. Loops allow you to iterate through each item in a collection one at a time, performing actions on individual records. When you create a Loop element, you specify which collection to iterate through and define a loop variable that temporarily holds the current item during each iteration. Inside the loop, you can add assignment elements to modify field values, decision elements to apply conditional logic, or other elements to perform specific operations. A common pattern involves creating an empty collection before the loop, then using Assignment elements within the loop to add modified records to this new collection. After the loop completes, you use a single Update Records element to save all changes in one database operation, which is crucial for avoiding governor limits. Best practices include minimizing the number of elements inside loops to improve performance, avoiding DML operations (Create, Update, Delete) within loops, and using bulk patterns by collecting records first and then performing a single database operation after the loop ends. Understanding loops and collections is fundamental for building scalable automations that handle large data volumes while respecting Salesforce platform limits and maintaining optimal performance.
Flow Loops and Collections: Complete Guide for Salesforce Administrators
Why Flow Loops and Collections Are Important
Flow Loops and Collections are fundamental concepts that enable administrators to process multiple records efficiently within Salesforce Flow. Understanding these concepts is critical because most real-world business processes involve handling bulk data rather than single records. Mastering loops and collections allows you to build scalable, governor-limit-friendly automations that can handle thousands of records at once.
What Are Collections?
Collections in Flow are variables that can hold multiple values of the same data type. Think of them as containers or lists that store numerous items together. There are three main types of collections:
Record Collections - Store multiple Salesforce records (e.g., a list of Contacts or Opportunities) Text Collections - Store multiple text values Number Collections - Store multiple number values
Collections are created using Get Records elements, Assignment elements, or as outputs from certain Flow actions.
What Are Loops?
A Loop element in Flow iterates through each item in a collection one at a time. For each iteration, the loop assigns the current item to a loop variable, allowing you to perform operations on that specific item before moving to the next one.
How Flow Loops and Collections Work Together
The typical pattern involves these steps:
1. Retrieve Records - Use a Get Records element to query Salesforce and store results in a record collection variable
2. Create a Loop - Add a Loop element that iterates through the collection
3. Process Each Record - Inside the loop, perform your logic on the current loop variable (decisions, assignments, etc.)
4. Build an Output Collection - Use Assignment elements to add modified records to a new collection
5. Perform DML Outside the Loop - After the loop completes, use a single Update Records or Create Records element on the entire output collection
Best Practices for Bulkification
The golden rule is: Never place DML operations (Create, Update, Delete) inside a loop. This causes governor limit issues because each iteration consumes a DML statement. Instead:
- Create an empty record collection variable before the loop - Inside the loop, add records to this collection using Assignment - After the loop ends, perform one DML operation on the entire collection
Exam Tips: Answering Questions on Flow Loops and Collections
Tip 1: Recognize Bulkification Scenarios When a question describes updating multiple records, look for answers that place Update/Create elements AFTER the loop, not inside it. Answers placing DML inside loops are typically incorrect.
Tip 2: Understand Loop Variables The loop variable represents ONE record at a time during each iteration. Questions may test whether you understand that modifications to the loop variable must be added to a separate collection for processing.
Tip 3: Know Your Collection Types Record collection variables can only store records of a single object type. A collection of Accounts cannot also contain Contacts.
Tip 4: Get Records Returns Collections When a Get Records element is configured to retrieve multiple records, it stores them in a record collection. Single record retrieval uses a record variable instead.
Tip 5: Empty Collection Handling Be aware that loops on empty collections simply skip the loop entirely - they do not cause errors. Questions may test this behavior.
Tip 6: Assignment Element Operations Know the difference between 'Add' (appends to collection) and 'Equals' (replaces entire collection) operators when working with collections in Assignment elements.
Tip 7: Watch for Governor Limit Questions Scenarios involving large data volumes (hundreds or thousands of records) are testing your knowledge of proper bulkification patterns. The correct answer will always involve processing collections efficiently.
Common Exam Question Patterns
- Scenario asks how to update all related child records - Answer involves Get Records, Loop, and Update Records after the loop - Question about reducing DML statements - Answer involves collecting records and performing single DML operation - Problem with Flow hitting limits - Solution involves moving DML operations outside of loops