Flow Performance: The Bulkification Patterns That Actually Matter
Salesforce flows run in bulk by default when triggered by data loads, but most admins build them assuming one record at a time. The flow engine tries to bulkify Get Records and Update Records elements automatically, but it fails silently when you break the pattern. Your flow works perfectly for one record and crashes at 200.
The core rule: never reference {!$Record} fields inside a Get Records filter that changes per record. Instead, collect the IDs you need into a collection variable before the loop, then do a single Get Records using an "IN" filter. For updates, build a collection of records to update inside the loop, then do a single Update Records element after the loop exits. This turns N queries into 1.
Watch out for Decision elements inside loops that branch to different DML operations. Each unique path through a flow counts as a separate DML statement. If your loop has a Decision with two Update Records elements (one per branch), you burn 2 DML per iteration instead of batching. Restructure so all records funnel into collection variables, then execute DML once after the loop.
Code Example
// BAD: DML inside loop (200 records = 200 DML operations)
// Loop → Decision → Update Records (per record)
// GOOD: Collect, then DML once
//
// Before Loop:
// Create variable: {!recordsToUpdate} (Record Collection)
//
// Inside Loop:
// Assignment: Add {!currentRecord} to {!recordsToUpdate}
//
// After Loop:
// Update Records: {!recordsToUpdate}
// (1 DML operation regardless of collection size)
//
// For mixed updates (different field values per record):
// Inside Loop:
// Assignment: Set {!currentRecord.Status__c} = "Processed"
// Assignment: Add {!currentRecord} to {!recordsToUpdate}
// After Loop:
// Update Records: {!recordsToUpdate}Need this implemented in your org?
I've shipped these patterns in production for 10+ years.
View Consulting →Enjoyed this? Get more like it.
Glen's Musings — AI, investing, and building things. Occasional. Free.
More Flows Tips
Debugging Flows Like a Developer: Beyond the Debug Log
Most admins debug flows by clicking "Debug" in Flow Builder and stepping through manually. That works for simple flows, ...
Read moreIntermediateScheduled Flow Gotchas: The 250K Record Trap and Batch Windows
Scheduled flows look simple: pick an object, set criteria, choose a schedule, done. But there are three gotchas that wil...
Read more