Sub topic 4
Data and logic elements you will use most
This chapter assumes you know Salesforce objects, fields, and records, and that you have opened Flow Builder. It covers the six elements that make up most scheduled and autolaunched flows.
The elements at a glance
| Element | Purpose | Common gotcha |
|---|---|---|
| Get Records | Reads records into a variable | Returns nothing if no record matches |
| Create Records | Inserts one or many records | Counts as one DML statement |
| Update Records | Changes existing records | Needs the record Id to be present |
| Delete Records | Removes records | Deletion is hard to undo. Filter carefully |
| Decision | Routes the flow by conditions | Unmatched records follow the default outcome |
| Assignment | Sets variable values | Does not save anything to the database |
| Loop | Visits each item in a collection | Putting DML inside it hits limits |
Reading data with Get Records
Get Records needs an object and filter conditions. You then choose to store only the first record or all matching records. "Only the first record" fills a single record variable. "All records" fills a record collection variable.
After a Get Records, check whether it found anything. A Decision that tests whether the variable "Is Null" equals false prevents later elements from working on empty data.
Branching with Decision
A Decision evaluates its outcomes in order from top to bottom. The first outcome whose conditions are true wins. If none match, the flow takes the default outcome. Name the default outcome clearly, for example "No stale cases", so the canvas reads like a sentence.
Changing values with Assignment
An Assignment changes variables in memory. You pick a variable, an operator, and a value. Common operators are Equals, Add, and, for collections, Add (append an item). Nothing reaches the database until an Update, Create, or Delete element runs.
Processing a collection with Loop
A Loop takes a collection and hands you one item at a time in a loop variable. The standard bulk-safe pattern has three steps:
- Get Records into a collection.
- Loop over it, and use Assignment to change the loop variable's fields. Then add that variable to a second collection.
- After the loop ends, run one Update Records on the second collection.
Updating without a loop
If you only need to set the same value on every matching record, use Update Records with filter conditions. No Get Records or Loop is needed. Salesforce handles the whole set at once, which is simpler and faster.
Exercise
A flow gets 500 cases into a collection, loops over them, and puts an Update Records element inside the loop. What problem will occur, and how do you fix it?
Show answer
Each loop pass runs a separate DML statement, so the flow hits the 150 DML statement limit and fails. Move the change into an Assignment that adds each modified case to a second collection. Then run one Update Records on that collection after the loop.