Sub topic 2
What a Workflow Rule does: criteria and actions
This chapter assumes you know Setup navigation and objects, fields, and records. It also assumes you can read basic formula syntax. A Workflow Rule is the older of the two tools you will be replacing, so you need to read one accurately before you translate it. A migration usually goes wrong because someone misreads when a rule fires or what its field updates trigger, not because the new tool is hard.
The shape of a Workflow Rule
A Workflow Rule belongs to exactly one object. It has three parts:
- Evaluation criteria that say when Salesforce checks the rule.
- Rule criteria that say which records qualify.
- Actions, grouped as immediate actions or time-dependent actions.
Evaluation criteria
The evaluation criteria control when the rule is considered. There are three options.
| Option | When the rule is evaluated | Time-dependent actions allowed |
|---|---|---|
| Created | Only when a record is first created | Yes |
| Created, and every time it's edited | On every create and every edit | No |
| Created, and any time it's edited to subsequently meet criteria | On create, and on an edit that moves the record from not matching to matching | Yes |
The third option is the one most often misread. It does not mean "run on every edit while the criteria are true." It runs when the record goes from not meeting the criteria to meeting them. If a record already meets the criteria and a user edits another field, the rule stays quiet. When you later build the flow, this behavior decides whether you need an entry condition that compares $Record with $Record__Prior, or whether a simple "only when a record is updated to meet the condition requirements" setting is enough. The entry conditions chapter covers that mapping.
The second option is the broadest. It fires its immediate actions on every save of a matching record, so a rule with this setting can send an email each time someone edits an unrelated field. Teams often forget this and later find that the migrated flow sends fewer emails than the old rule did.
Rule criteria
Rule criteria decide which records qualify, in one of two ways:
- Filter criteria: field, operator, and value rows combined with AND by default, or with custom filter logic such as
1 AND (2 OR 3). - Formula: any formula that returns true or false.
Formula criteria support functions that you cannot always copy straight into a flow. The most common differences are picklist handling and change detection.
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}Notice that ISPICKVAL becomes TEXT(). Also, ISCHANGED has no flow formula equivalent, so the flow compares the current record with its prior values. Both rewrites are needed any time a formula touches a picklist or detects a change.
Rule formulas can also use ISNEW() to test for creation. You will see it in rules set to evaluate on every edit, where it distinguishes inserts from updates inside one rule.
Immediate actions
Immediate actions run in the same transaction as the save. A Workflow Rule supports only four action types:
- Field update: sets a field on the same record, or on the parent record for a master-detail relationship in some cases. It can set a literal value, a null, or the result of a formula, and it can reassign the owner.
- Email alert: sends an email from a template to recipients you choose, such as the record owner, a role, or a related user.
- Task: creates a task related to the record, with an assignee and a due date calculated from the rule trigger date.
- Outbound message: sends a SOAP message to an external endpoint.
Workflow Rules cannot create arbitrary records, call Apex, or post to Chatter. Those abilities arrived with Process Builder. When you inventory rules, this narrow list helps you predict the flow elements you will need. A field update becomes an Update Records element or, in a before-save flow, a direct assignment. An email alert becomes an Action element, and a task becomes a Create Records element. An outbound message needs more thought, and a later chapter covers it.
The re-evaluate setting on field updates
A field update has a checkbox, Re-evaluate Workflow Rules after Field Change. When it is on and the update actually changes the value, Salesforce runs the workflow rules on that record again. This is how chains of rules form: rule A sets a field, which makes rule B's criteria true, which runs rule B.
Field updates from workflow also cause the record's before and after update triggers to fire one more time, even without the checkbox. Rules built on this behavior look fine in the Setup UI but form hidden chains. Write down any rule that has the checkbox on, because the flow that replaces it must reproduce the chain deliberately or remove it.
Time-dependent actions
A time-dependent action runs a set number of hours or days before or after a date. The date is either a field on the record, such as CloseDate, or the rule trigger date. For example: "send a reminder 3 days before CloseDate."
Each action belongs to a time trigger, and a rule can have several. When the rule fires, Salesforce places the pending actions in a time-based queue. At the scheduled time, it re-checks the rule criteria. If the record no longer meets them, the queued actions are discarded. This self-cancelling behavior is easy to overlook. A flow scheduled path does not always cancel the same way, so a migrated rule may send emails the original would have dropped. The scheduled paths chapter handles this.
You can inspect pending actions under Setup > Time-Based Workflow. This is also a useful check before a cutover, because deactivating a rule leaves its already-queued actions unresolved until you decide what to do with them.
Reading a rule in the org
Use the Tooling API to list rules and the objects they belong to. This gives you a starting list you can group by object.
SELECT Id, Name, TableEnumOrId
FROM WorkflowRuleTableEnumOrId shows a standard object's API name, such as Opportunity. For a custom object it shows the object's Id. Matching these Ids to object names takes an extra lookup. The query returns only the rule's identity, so open each rule in Setup to read its evaluation criteria, formula, and actions.
A worked reading
Suppose a rule is on Opportunity with these settings:
- Evaluation criteria: created, and any time it's edited to subsequently meet criteria.
- Rule criteria:
AND(ISPICKVAL(StageName, "Closed Won"), Amount > 100000). - Immediate action: an email alert to the account owner.
- Time-dependent action: a task 7 days after
CloseDate.
Read it in plain words. The rule fires once when an opportunity reaches Closed Won with an amount over 100,000, or when it is created that way. It emails the account owner right away. It also queues a task for seven days after the close date, and that task disappears if the opportunity stops meeting the criteria first. Every part of that description needs a counterpart in the flow you build.
Exercise
A Workflow Rule uses "created, and any time it's edited to subsequently meet criteria" with the criteria Status = Escalated. A user edits the Description of a case that is already Escalated. Does the rule's email alert fire? Would your answer change if the setting were "created, and every time it's edited"?
Show answer
With the "subsequently meet criteria" setting, the alert does not fire. The case already met the criteria before the edit, so the record did not move from not matching to matching. With "created, and every time it's edited", the alert fires, because the rule is evaluated on every save and the case still meets the criteria.