Question

Difficulty: MediumFlow Resources and Data Manipulation

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?

  1. 1Retrieve the set of related Opportunity records using a Get Records element outside of any loop.
  2. 2Iterate through the collection of retrieved Opportunity records using a Loop element.
  3. 3Modify the field values on the current loop item variable using an Assignment element inside the loop.
  4. 4Add the modified current loop item variable to a new output record collection variable using an Assignment element inside the loop.
  5. 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

1
Query related records
Obtain a record collection variable containing all related Opportunity records.
Data must be retrieved prior to iterating over records.
2
Begin loop iteration
Pass control to the Loop element to process one record at a time.
Iteration allows individual record inspection and variable manipulation.
3
Update record field values
Stage the updated field values on the current item record variable.
Values are updated in memory first using an Assignment element.
4
Add to output collection
Append the modified current record variable to an output record collection variable.
Combining records into a collection variable enables bulk DML operations.
5
Execute bulk DML update
Update all modified Opportunity records in Salesforce in a single database transaction.
Placing the Update Records element after the loop prevents hitting SOQL/DML governor limits.

Key Concept

Bulkification in Salesforce Flow using Record Collections and Assignment elements
Rate this question