Question

Difficulty: HardFlow Resources and Data Manipulation

An administrator is building a Screen Flow that enables users to enter details for multiple new Contact records associated with a parent Account within a continuous entry loop. To avoid reaching database governor limits, all Contact records must be created in a single transaction after the user completes the loop. Which combination of Flow resources and elements should the administrator use to achieve this requirement?

  1. Populate a Record Single Variable inside the loop, add it to a Record Collection Variable using an Assignment element inside the loop, and place a single Create Records element after the loop referencing the collection variable.Answer
  2. B
    Populate a Record Single Variable inside the loop, and place a Create Records element directly inside the loop to insert each record on every iteration.
  3. C
    Assign field values directly to a Get Records element inside the loop, and execute an Update Records element inside the loop for each Contact record.
  4. D
    Execute a Get Records element inside the loop to populate a Record Collection Variable on each iteration, then place an Update Records element after the loop without an Assignment element.

Answer

Populate a Record Single Variable inside the loop, add it to a Record Collection Variable using an Assignment element inside the loop, and place a single Create Records element after the loop referencing the collection variable.
The correct option adheres to Salesforce Flow design best practices for bulkification. By staging record values in a Record Single Variable, using an Assignment element to append that single variable to a Record Collection Variable during each iteration, and placing a single Create Records element outside the loop, the flow performs only one DML call regardless of how many records are generated.

Step-by-Step Solution

1
Create required Flow resources.
Define one Record Single Variable for Contact records (to temporarily hold values for each iteration) and one Record Collection Variable for Contact records (to hold all accumulated records).
A record collection resource is necessary to hold multiple records in memory prior to executing a single DML operation.
2
Populate values and stage the collection within the loop.
Assign values from screen components to the Record Single Variable, then use an Assignment element with the 'Add' operator to append the Record Single Variable to the Record Collection Variable.
Using an Assignment element inside the loop updates in-memory variables without issuing database calls.
3
Perform database commit after loop completion.
Place a single Create Records element on the path after the loop finishes, passing the Record Collection Variable as the target.
Placing DML elements outside the loop ensures all records in the collection are created using a single bulk transaction.

Key Concept

Bulkification of Flow DML operations using Record Collection Variables and Assignment elements
Rate this question