Loops and bulk DML in Flow Builder
Key Takeaway
Inside a loop, use an Assignment element to add each record to a record collection variable. After the loop, one Create Records or Update Records element saves the whole collection.
A Loop element lets a flow work through a collection one item at a time and run the same elements on each item. Bulk DML means saving all record changes in one step after the loop instead of once per item. Every Get Records element counts against per-transaction governor limits, and so does every Create Records, Update Records, and Delete Records element. A loop multiplies those counts.
How a Loop element works
A Loop element takes a collection variable and sends each item, one at a time, down its For Each path. After the last item, the flow leaves the loop on the After Last path.
The Loop element has these fields:
- Collection Variable: the collection to loop through.
- Direction: whether to start with the first item or the last item.
- Loop Variable: the variable that the loop copies the current item into on each pass.
The loop variable is named "Current Item from Loop", and its type depends on what the collection holds:
| Collection holds | Current Item from Loop is |
|---|---|
| Records | A record variable of the same object, such as an account record variable |
| Plain values, such as record IDs | A variable of the same data type, such as text |
Elements on the loop path can reference Current Item from Loop. Resources such as text templates, formulas, and variable default values can reference it too.