Question

Difficulty: Very hardFlow Resources and Data Manipulation

An administrator needs to build an autolaunched Flow that updates the Mailing Street address on all Contact records associated with a modified Account record. To strictly comply with Salesforce apex governor limits, in what sequence should the administrator configure the Flow resources and elements to perform this data manipulation?

  1. 1Execute a Get Records element to query all Contact records related to the Account ID into a record collection variable.
  2. 2Pass the record collection variable into a Loop element to process each Contact record individually.
  3. 3Use an Assignment element within the loop to update field values on the current item loop variable.
  4. 4Use a second Assignment element within the loop to add the updated current item loop variable to a separate update collection variable.
  5. 5Place an Update Records element on the After Last loop path to persist the update collection variable to the database.

Answer

The correct sequence starts with querying records using a Get Records element into a collection, iterating through the collection with a Loop element, modifying fields on the current loop item via an Assignment element, adding the modified item to an update collection variable via a second Assignment element inside the loop, and finally executing a single Update Records element after the loop completes.
Bulkifying Salesforce Flows requires separating memory-based data manipulation from database operations. The proper architecture performs a single Get Records query before entering the Loop, uses Assignment elements inside the loop to alter values and stage items into a new collection variable in memory, and finishes with a single Update Records element placed after the loop path completes.

Step-by-Step Solution

1
Query related child records in bulk
A record collection variable containing all related Contact records is created with a single SOQL query.
Fetching records before entering any iteration avoids executing queries inside a loop.
2
Iterate through the collection variable
The Loop element begins stepping through each record item individually.
Flow logic requires iterating through collection items to evaluate or modify individual record attributes.
3
Stage record field updates in memory
The current loop item's field values are updated in local memory.
Values must be assigned to the current loop item variable before it can be appended to an update collection.
4
Collect modified records into a single collection variable
The updated loop item variable is added to an output update collection variable using the Add operator.
Aggregating modified items into a dedicated collection prepares all records for a single, bulkified DML statement.
5
Persist collection updates to Salesforce database
The Update Records element executes outside the loop, committing changes for all collection items at once.
Invoking DML elements outside of loops enforces bulkification best practices and prevents hitting the 150 DML statement limit per transaction.

Key Concept

Flow Bulkification and Collection Data Manipulation
Rate this question