Question

Difficulty: MediumFlow Resources and Data Manipulation

An administrator is designing a record-triggered flow to archive all Campaign Member records when a parent Campaign is marked as 'Completed'. To ensure optimal performance and prevent hitting governor limits, the flow must properly manipulate memory resources and bulkify record updates.

In which order should the administrator sequence the Flow elements and data manipulation steps to achieve this requirement?

  1. 1Retrieve related Campaign Member records into a collection using a Get Records element.
  2. 2Iterate through each Campaign Member in the collection using a Loop element.
  3. 3Set the Status field value on the current loop record variable using an Assignment element.
  4. 4Add the updated current loop record variable to a new record collection variable using an Assignment element.
  5. 5Perform a single DML update on the staged record collection variable using an Update Records element after the loop finishes.

Answer

The correct sequence is: (1) Retrieve related Campaign Member records into a collection using a Get Records element, (2) Iterate through each Campaign Member in the collection using a Loop element, (3) Set the Status field value on the current loop record variable using an Assignment element, (4) Add the updated current loop record variable to a new record collection variable using an Assignment element, and (5) Perform a single DML update on the staged record collection variable using an Update Records element after the loop finishes.
The standard, bulkified Salesforce Flow design pattern dictates that records are first retrieved into a collection (Get Records), iterated individually (Loop), updated in memory (Assignment on current item), accumulated into a secondary collection (Assignment with Add operator), and finally updated in the database as a single transaction after the loop terminates (Update Records).

Step-by-Step Solution

1
Query the required Campaign Member records using a Get Records element.
A record collection variable containing all related Campaign Member records.
Records must be fetched from the database into flow memory before any operations or loops can process them.
2
Feed the retrieved record collection into a Loop element.
The flow begins iterating through records individually via the Current Item from Loop variable.
A Loop element is required to isolate and access individual record fields from a multi-record collection.
3
Use an Assignment element to assign the new Status value to the current loop item.
The in-memory record variable reflects the modified field value.
Field changes must be made to the loop variable in memory before staging it for persistence.
4
Use an Assignment element with the 'Add' operator to push the current loop item into an update collection variable.
The staging collection accumulates all modified record instances across loop cycles.
Aggregating updated records in a collection enables a single batch DML transaction outside the loop.
5
Connect the 'After Last Item' path of the Loop to an Update Records element referencing the update collection variable.
All modified records are committed to the database in one DML statement.
Placing the DML operation outside the loop satisfies governor limit bulkification best practices.

Key Concept

Flow bulkification design pattern utilizing Assignment elements to stage modified record variables into a collection for a single DML operation outside a Loop.
Estimated Time:1m 15s
Rate this question