Notes
To ensure a Flow is bulk-safe, you must design it to handle multiple records efficiently while staying within Salesforce governor limits. Here are the key practices:
1. Minimize SOQL and DML Operations
- Use Get Records and Update Records elements outside loops to avoid hitting SOQL and DML limits.
- Use Collection Variables to group records and perform bulk operations in a single step.
2. Use Bulk-Safe Elements
- Prefer using elements that inherently support bulk processing, such as Fast Field Updates and Fast Record Lookup in certain Flow types.
3. Optimize Loops
- Avoid performing DML or SOQL operations inside loops. Instead, collect the data in a variable during the loop and perform a single bulk operation afterward.
- For example, in a Flow iterating through records, gather IDs into a collection and update them all at once after the loop.
4. Test with Bulk Data
- Test the Flow with a large number of records to simulate real-world scenarios and identify potential bulk-processing issues.
5. Handle Errors Gracefully
- Implement Fault Paths to handle errors and avoid Flow termination when processing bulk records.
6. Check Governor Limits
- Keep an eye on Salesforce governor limits, such as:
- 100 SOQL queries per transaction.
- 150 DML statements per transaction.
- 200,000 CPU time limit in synchronous Flows.
7. Leverage Apex Where Needed
- If a Flow's logic becomes too complex or risks breaching governor limits, consider offloading certain parts to an invocable Apex class, which can handle bulk processing more efficiently.