An administrator is designing an autolaunched Flow to update a field across multiple child records processed within a Loop element. To follow Salesforce best practices and prevent hitting DML governor limits, how should the data manipulation elements be configured?
- Add updated records to a Record Collection Variable inside the loop, then execute a single Update Records element outside the loop.Answer
- BPlace an Update Records element inside the Loop element to update each record individually during every iteration.
- CPlace a Get Records element inside the Loop element to fetch updated values before applying an immediate update.
- DUse an Assignment element inside the loop to commit DML changes directly to the database for each record.
Answer
Collect the modified records into a record collection variable inside the loop using an Assignment element, and execute a single Update Records element after the loop finishes.
Salesforce governor limits dictate that DML elements (Create, Update, Delete) and SOQL queries (Get Records) should never be placed inside loops. The recommended pattern is to modify records in memory, add them to a record collection variable using an Assignment element inside the loop, and then perform a single bulk DML operation using an Update Records element outside the loop.
Step-by-Step Solution
Key Concept
Flow Bulkification and Loop Placement Best Practices