Question

Difficulty: Very hardFlow Resources and Data Manipulation

An administrator is tasked with updating the entitlement status and expiration dates on hundreds of custom Contract Line Item records whenever a parent Contract status changes to 'Expired'. The solution must update all related records reliably while adhering to Salesforce governor limits.

Which design pattern should the administrator implement in Flow Builder to perform this data manipulation efficiently?

  1. Loop through the retrieved Contract Line Items, use an Assignment element inside the loop to update the field values on the current item and append that item to a new Record Collection Variable, and place an Update Records element outside the loop referencing the new collection.Answer
  2. B
    Loop through the retrieved Contract Line Items and place an Update Records element directly inside the loop to save field changes to Salesforce on each iteration.
  3. C
    Loop through a collection of Contract Line Item IDs, execute a Get Records element inside the loop to retrieve each record's full details, modify the fields, and execute an Update Records element outside the loop.
  4. D
    Use a Create Records element inside the loop to generate clone records with the updated status, then execute a Delete Records element outside the loop to remove the original records.

Answer

Iterate through the line item collection using a Loop element, use an Assignment element inside the loop to update the current item variable and add it to a target Record Collection Variable, then execute a single Update Records element outside the loop.
The correct approach follows Salesforce bulkification best practices. By updating field values on the loop item variable and assigning that item to a separate Record Collection Variable within the loop, all record changes are staged in memory. A single Update Records element placed after the loop processes the entire collection in one database transaction, ensuring scalability and compliance with governor limits.

Step-by-Step Solution

1
Query related child records prior to entering the loop.
Obtain a Record Collection Variable containing all target Contract Line Item records.
Retrieving data in bulk before processing avoids running SOQL queries inside the loop.
2
Iterate over the collection using a Loop element.
Pass each individual record to the current item loop variable.
Allows field assignment logic to execute on one record at a time in memory.
3
Use an Assignment element inside the loop to update fields and add the loop variable to a secondary Record Collection Variable.
The modified record is stored in memory within the secondary collection.
Accumulates all updated records without issuing immediate database commits.
4
Place a single Update Records element after the loop finishes and pass the secondary Record Collection Variable.
Salesforce performs a single bulkified DML operation for all records in the collection.
Prevents hitting the governor limit of 150 DML statements per transaction.

Key Concept

Bulkification in Flow Builder using Assignment elements and Record Collection Variables
Rate this question