Sub topic 3
What a Process Builder process does: nodes and actions
This chapter assumes you can open Setup and Process Builder, read a formula, and recognize an object, field, and record. You don't need to have built a flow yet. Here you learn how a process is put together, so that later chapters can translate each part into a record-triggered flow.
What a process is
A process is an automation built in Process Builder. It is a flow underneath. Salesforce stores it as a flow definition with the process type Workflow, which is why you can find processes with a query, shown near the end of this chapter.
A process has three parts:
- A trigger that decides what starts the process.
- One or more criteria nodes that test the record.
- Actions attached to each node, either immediate or scheduled.
A process always works on one object, or on one event type, and it is versioned. Only one version can be active at a time.
The trigger
The start element offers three ways to begin a process:
- A record changes. You pick an object and choose "only when a record is created" or "when a record is created or edited". Most processes you will migrate use this.
- A platform event message is received. The process runs when an event of the chosen type is published.
- It is invoked by another process. This is an invocable process. It has no trigger of its own and runs only when another process calls it.
For record-change processes, the start element also has a recursion setting. It reads "Allow process to evaluate a record multiple times in a single transaction". When it is on, an update made by the process (or by a workflow field update) can start the process again within the same transaction. Note this setting now. It affects how you design the replacement flow.
Criteria nodes
After the trigger, the process evaluates its criteria nodes from top to bottom. Each node has a name and one of three criteria types:
- Conditions are met. You add rows of field, operator, and value. You choose "all", "any", or custom logic such as
(1 AND 2) OR 3. A value can be a literal, a field reference, a formula, or a global constant. - Formula evaluates to true. You write one Boolean formula, which can use
ISNEW(),ISCHANGED(), andPRIORVALUE(). - No criteria. The actions always run.
A formula criterion looks like this. Merge fields are written in square brackets with the object name, and picklists need ISPICKVAL:
AND(
ISCHANGED([Opportunity].StageName),
ISPICKVAL([Opportunity].StageName, "Closed Won"),
[Opportunity].Amount > 100000
)Run only on a change
When a node uses "Conditions are met", the node also has an advanced checkbox: "Execute the actions only when specified changes are made to the record". With this on, the node fires only when the record changes from not matching to matching. With it off, the node fires on every edit where the conditions are true.
This distinction is the most common source of surprises in migrations. A process without the checkbox that was meant to fire once may actually have been firing on every save.
Continue or stop
Each node ends with a choice. After its actions, the process either evaluates the next criteria node or stops. If you picked "stop", later nodes don't run for that record. If you picked "evaluate the next criteria", every later node is tested too, so several nodes can fire for one save.
Immediate and scheduled actions
Each criteria node can hold two groups of actions.
Immediate actions run in the same transaction as the save, after the record is committed to the database but before the transaction ends. A process is an after-save automation. Any change it makes to the triggering record is a second update. That update can fire triggers, workflow rules, and other automation again.
Scheduled actions run later. You set a time reference and an offset:
- The time reference is either a date or date/time field on the record, such as
CloseDate, or the time the process evaluated the criteria. - The offset is a number of days or hours, before or after the reference.
When a scheduled time arrives, the process rechecks the criteria. If the record no longer qualifies, the pending action is dropped. Editing the record can therefore cancel work that was queued earlier.
Action types
| Action | What it does |
|---|---|
| Create a Record | Creates a record of any object you can write to, with field values you set. |
| Update Records | Updates the triggering record, or related records found through lookup relationships, including child records filtered by conditions. |
| Email Alerts | Sends an existing email alert, which carries its own template and recipients. |
| Post to Chatter | Posts to a record's feed or a group. |
| Quick Action | Runs an existing quick action, such as creating a related record from a layout. |
| Submit for Approval | Submits the record to an approval process. |
| Flow | Launches an autolaunched flow and passes it values. |
| Apex | Calls an `@InvocableMethod`. |
| Process | Calls an invocable process. |
| Send Custom Notification | Sends a custom notification to users. |
Scheduled groups can hold the same types. Later chapters map each of these to a flow element.
A process end to end
Suppose a process on Opportunity has two nodes:
- "Big deal won": formula criteria as above. Immediate actions create a follow-up Task and send an email alert. A scheduled action updates a field 7 days after
CloseDate. The node ends with "evaluate the next criteria". - "Any win": the condition
StageNameequalsClosed Won, with no changes-only checkbox. The immediate action posts to Chatter.
For a $150,000 deal that just closed, both nodes fire. For a $20,000 deal, only node 2 fires. Seven days after the close date, the queued update runs only if the record still meets node 1's criteria.
Settings to record before migrating
When you document a process for migration, write down these details. They change how the flow must be built:
- The trigger choice (create only, or create and edit).
- The recursion checkbox.
- For each node, the criteria type and whether the changes-only box is checked.
- The continue-or-stop choice after each node.
- The time reference and offset of every scheduled action.
- Any actions that call Apex, flows, or other processes, because those carry dependencies.
Finding processes in your org
Processes are flow definitions, so you can list the active ones. Run this in the Developer Console Query Editor with the Tooling API option checked, or in a Tooling API client:
SELECT ApiName, Label, ProcessType, IsActive
FROM FlowDefinitionView
WHERE ProcessType = 'Workflow' AND IsActive = trueExercise
A process has one criteria node using "Conditions are met" with Status equal to Escalated. The "Execute the actions only when specified changes are made to the record" box is unchecked, and the node creates a Task. A user edits an already escalated Case's Description. What happens, and what would change if the box were checked?
Show answer
With the box unchecked, the conditions are still true on that edit, so the node fires and creates another Task. With the box checked, the node fires only when the record changes from not matching to matching. Editing the Description of a Case that was already Escalated would not create a Task.