An administrator is designing a record-triggered flow to update the stage and probability of multiple related Opportunity records when an Account is downgraded. To follow Salesforce best practices and avoid hitting governor limits, in what order should the data manipulation elements and variable operations be executed within the flow?
- 1Retrieve the set of related Opportunity records using a Get Records element outside of any loop.
- 2Iterate through the collection of retrieved Opportunity records using a Loop element.
- 3Modify the field values on the current loop item variable using an Assignment element inside the loop.
- 4Add the modified current loop item variable to a new output record collection variable using an Assignment element inside the loop.
- 5Commit all changes to the database using an Update Records element on the output collection variable after the loop completes.
Answer
The correct sequence starts with querying records into a collection via Get Records, iterating through the collection with a Loop element, updating field values on the current item via Assignment, adding the current item to a target output collection via Assignment, and finally issuing a single Update Records DML operation outside the loop.
Following Salesforce bulkification design principles, data retrieval (Get Records) occurs first to instantiate a record collection. Next, a Loop element iterates through each item. Inside the loop, field modifications are made to the current record variable using an Assignment element, and a second Assignment element adds that modified record to a separate output collection. Once the loop finishes processing all items, a single Update Records element executes on the output collection outside the loop to commit changes efficiently.
Step-by-Step Solution
Key Concept
Bulkification in Salesforce Flow using Record Collections and Assignment elements