Question

Difficulty: HardFlow Resources and Data Manipulation

An administrator is creating an autolaunched flow to process a collection of Contract records associated with an Account whenever the Account tier is upgraded. The flow must update the Status field to 'In Review' on each associated Contract record and persist these changes back to Salesforce. Which design pattern should the administrator implement to ensure the flow executes efficiently without hitting governor limits?

  1. Iterate through the Contract collection using a Loop element, use an Assignment element inside the loop to set updated field values on the current item and append it to a target Record Collection Variable, and place a single Update Records element outside the loop referencing the target collection.Answer
  2. B
    Iterate through the Contract collection using a Loop element, update the field values on the current record item, and execute an Update Records element inside the loop during each iteration.
  3. C
    Place a Get Records element inside a Loop element to re-fetch each Contract record, update the values directly on the retrieved record, and invoke a single Update Records element at the end of the flow referencing the Account record.
  4. D
    Use a Decision element inside a Loop element to clear the existing collection, assign the modified values to a single Record Variable, and execute a Create Records element inside the loop to insert duplicate contracts.

Answer

Iterate through the Contract collection using a Loop element, use an Assignment element inside the loop to set updated field values on the current item and append it to a target Record Collection Variable, and place a single Update Records element outside the loop referencing the target collection.
To process multiple records efficiently in Salesforce Flow, field assignments should be staged in memory using an Assignment element inside the Loop. The modified items are added to a separate Record Collection Variable, and a single Update Records element is executed outside the loop to commit all updates in bulk.

Step-by-Step Solution

1
Iterate over the collection of Contract records
Each record item is made available sequentially within the Loop element context.
Allows memory-based field modifications for every record in the collection.
2
Modify fields and add to an output collection variable using an Assignment element inside the loop
Field changes are stored in memory and added to a target Record Collection Variable.
Prevents database transactions inside loop iterations.
3
Execute a single Update Records element outside the loop
All updated records in the target Record Collection Variable are persisted to Salesforce in one bulk DML statement.
Adheres to Salesforce governor limits by executing only one DML statement regardless of collection size.

Key Concept

Flow Bulkification and Collection Processing
Rate this question