Sub topic 5
Flow Builder essentials for migrators
This chapter covers the parts of Flow Builder you need before you translate any Workflow Rule or process. It assumes you can already read a Workflow Rule or Process Builder process and write basic formulas. It also assumes you have a sandbox or Developer Edition org open. Later chapters cover the record-triggered details, such as before-save versus after-save, entry conditions, and scheduled paths.
Flow types and the ones that matter here
Flow Builder creates several kinds of flows. Migration work mostly uses one of them, but you will meet the others.
| Flow type | Starts when | Role in a migration |
|---|---|---|
| Record-triggered flow | A record is created, updated, or deleted | Replaces Workflow Rules and Process Builder processes |
| Schedule-triggered flow | A set date and frequency arrives | Replaces batch-style jobs, not time-dependent actions on a record |
| Autolaunched flow (no trigger) | Another flow, Apex, or a REST call invokes it | Reusable logic, such as a subflow that several flows share |
| Screen flow | A user opens it | Not part of migration |
| Platform event-triggered flow | A platform event message is published | Replaces processes that started from a platform event |
Process Builder could also be invoked by another process. In Flow, you do this by calling an autolaunched flow as a subflow.
The canvas and the Start element
Every flow has a Start element. On a record-triggered flow, Start holds the settings that Workflow Rules and processes kept in their criteria screens:
- The object.
- The trigger: created, updated, created or updated, or deleted.
- Entry conditions, which decide whether the flow runs for a given record.
- The optimization choice: Fast Field Updates (a before-save flow) or Actions and Related Records (an after-save flow).
- The run frequency for update triggers.
Everything after Start is a chain of elements connected by arrows. The flow follows the arrows from top to bottom for each record that passes the entry conditions.
Elements you will use most
Most migrated automation uses a small set of elements.
| Element | Purpose | Closest old concept |
|---|---|---|
| Decision | Branches by outcome. Each outcome has its own conditions, and a default outcome catches the rest. | Process Builder criteria nodes |
| Assignment | Sets values on variables or on `$Record` fields without touching the database | Nothing direct. It is a flow-only step. |
| Get Records | Queries records into a variable or collection | Process Builder lookups through formulas |
| Update Records | Writes changes to records | Field Update, Update Records action |
| Create Records | Inserts new records | Create a Record action, Task action |
| Delete Records | Deletes records | No Workflow or Process Builder equivalent |
| Loop | Iterates over a collection | Process Builder did this implicitly |
| Action | Calls an email alert, Apex, or another invocable action | Email Alert, Apex, Post to Chatter |
| Subflow | Runs another autolaunched flow | Flows launched from processes |
Assignment is the element that confuses migrators most. It changes values in memory only. Nothing is saved until the flow reaches an element that writes to the database. In a before-save flow, changes made to $Record through an Assignment are saved automatically with the triggering record.
Resources: variables, constants, and formulas
Resources are named values you create once and reference throughout the flow. A reference looks like {!resourceName}.
- A variable holds a value that can change. It has a data type, such as Text, Number, Boolean, or Record, and can be a single value or a collection.
- A constant holds a value that never changes.
- A formula resource calculates a value each time you reference it.
- A text template builds email bodies and messages with merge fields.
Mark a variable as available for input or output only when another flow, Apex, or a caller needs to pass data in or out. Otherwise leave it private.
Global variables
Record-triggered flows give you two record variables that matter in a migration:
{!$Record}is the record that triggered the flow, with its values after the change.{!$Record__Prior}is the record as it was before the update. It exists only in flows that fire on update, so a flow that runs only on create has no prior values.
The prior record replaces the PRIORVALUE() function and ISCHANGED() that Workflow Rules and processes used. Other globals include {!$Flow.CurrentDateTime}, {!$User}, {!$Organization}, and {!$Api}.
Formula syntax differences
Flow formulas use the same function library as other Salesforce formulas, with a few differences that surprise people during migration.
Workflow Rule formula:
AND(ISPICKVAL(StageName, "Closed Won"), Amount > 100000)
Flow entry condition (Formula Evaluates to True):
AND(TEXT({!$Record.StageName}) = "Closed Won", {!$Record.Amount} > 100000)
Workflow ISCHANGED(StageName) in a flow:
{!$Record.StageName} <> {!$Record__Prior.StageName}Three rules follow from this example:
- Fields are written as
{!$Record.FieldName}, never as a bare field name. - Picklist values are compared with
TEXT(), notISPICKVAL(). - There is no
ISCHANGED()in a flow formula. Compare$Recordwith$Record__Prior.
Working with data
Get Records, Update Records, Create Records, and Delete Records each run against the database, so each counts toward the same limits as Apex in the same transaction. These include 100 SOQL queries and 150 DML statements per synchronous transaction.
Two habits keep flows safe:
- Never put a data element inside a Loop. Collect changes in a collection variable during the loop, then write the whole collection once after the loop ends.
- In Get Records, retrieve only the fields you use, and choose "Only the first record" or "All records" deliberately. A flow that stores one record in a record variable is easier to read than one that loops over a one-item collection.
Record-triggered flows already process records in batches of up to 200, the same chunk size Apex triggers use. The flow runs once per batch, not once per record, which is why data elements inside loops cause problems at scale.
Fault paths
A Workflow Rule that failed rolled back the save and showed an error. A flow does the same by default: an unhandled error in a flow stops it, rolls back the transaction, and sends the flow's author an email.
For any element that can fail, such as Update Records, Create Records, or an Action, you can add a fault path. This is a separate connector that the flow follows when the element errors. The usual pattern is to store {!$Flow.FaultMessage} and then either log it to a custom object or stop the flow with a clear message. Migrated flows with no fault paths lose the error handling that you may have built around the old rules.
Versions, activation, and debugging
A flow is saved as versions. Only one version can be active at a time, and saving changes to an active flow creates a new version rather than overwriting the old one. Activating the new version deactivates the previous one. Keeping the older version lets you roll back by reactivating it.
The Debug button runs a flow from the canvas. For record-triggered flows you pick a record and see each element's inputs and outputs. You can run the debug in rollback mode, which discards the changes it makes, so you can test in a sandbox without altering data.
Common mistakes for new Flow users
- Treating Assignment as a save. Nothing is written to the database until a data element runs, except for
$Recordchanges in a before-save flow. - Leaving a flow in Draft after building it. Only an active version runs.
- Testing with one record. A flow that works on one record can still hit limits on 200.
- Forgetting that flow formulas need
{!...}merge syntax around every field.
Exercise
A Workflow Rule formula is AND(ISCHANGED(Status), ISPICKVAL(Status, "Escalated")). Write the equivalent Formula Evaluates to True condition for an update-triggered record-triggered flow on the same object.
Show answer
AND({!$Record.Status} <> {!$Record__Prior.Status}, TEXT({!$Record.Status}) = "Escalated"). ISCHANGED becomes a comparison of $Record and $Record__Prior, and ISPICKVAL becomes TEXT().
Exercise
A flow loops over 50 Contacts and runs an Update Records element inside the loop for each one. What should you change, and why?
Show answer
Add each modified Contact to a collection variable inside the loop, then use one Update Records element on the collection after the loop. Data elements inside a loop count toward limits once per iteration and can exceed the DML limit when batches are large.