Sub topic 9
Translating actions: field updates, emails, tasks, records, Apex
This chapter assumes you can read a Workflow Rule or Process Builder process and have built a simple record-triggered flow. It also assumes you have already turned the criteria into entry conditions. The task now is to move what happens after a record qualifies. Each legacy action has a flow counterpart. Some counterparts differ in when they run, what they can touch, or how they behave in bulk.
The action mapping at a glance
| Legacy action | Where it existed | Flow replacement | Save context |
|---|---|---|---|
| Field update on the triggering record | Workflow, Process Builder | Assignment or Update Records on `$Record` | Before-save preferred |
| Update related records | Process Builder | Get Records, then Update Records | After-save |
| Email alert | Workflow, Process Builder | Action element using the existing email alert, or Send Email | After-save |
| Task | Workflow, Process Builder | Create Records on Task | After-save |
| Create a record | Process Builder | Create Records | After-save |
| Invocable Apex | Process Builder | Action element calling the same Apex class | After-save |
| Launch a flow | Process Builder | Subflow element | Either, depending on the subflow |
| Outbound message | Workflow | See the chapter on actions without a direct equivalent | After-save |
Field updates on the triggering record
A Workflow field update and a Process Builder "Update Records" on the triggering record both write to the record that started the automation. In a flow, do this in a before-save flow whenever you can. A before-save flow changes the record before it is saved, so it needs no extra DML statement. It is also faster than the after-save equivalent.
In a before-save flow, use an Assignment element and set {!$Record.FieldName} to the new value. You do not add an Update Records element, because the platform saves your changes as part of the original operation.
Three differences from the old tools cause most errors:
- Workflow had a "Re-evaluate Workflow Rules after Field Change" option. Flows have no such option. If a second automation depends on the new value, it must be written as its own flow or merged into this one.
- Picklist formulas change. Wrap picklist fields in
TEXT()in flow formulas, where Workflow usedISPICKVAL. - A before-save flow cannot read values that the database sets later, such as the Id of a record being inserted.
Updating related records
Process Builder could update a parent or child record in one node. A flow needs two steps. Get Records finds the related record, and Update Records changes it. This work requires an after-save flow, because it modifies records other than the one being saved.
For a parent record, the Update Records element can use the lookup path from $Record, such as {!$Record.Account.Id}. For child records, use Get Records with a filter like AccountId = {!$Record.Id}. Then either update the whole collection in one element or loop over it.
Keep the update outside any loop. Inside the loop, use an Assignment element to change fields on a loop variable and add that variable to a collection variable. After the loop, run one Update Records on the collection. This pattern keeps the flow within DML limits when 200 records arrive together. The chapter on bulk safety covers the reasons in detail.
Email alerts
The simplest translation reuses what you have. Flow's Action element can call an existing email alert. Pick the alert by object and name, and pass {!$Record.Id} as the record Id. The template, recipients, and from-address stay exactly as they were. Reusing the alert avoids copying recipient logic, and you can delete the alert later once nothing references it.
If the old process built the message from scratch, use the Send Email core action. It takes a subject, a body, and a list of addresses. Add a Formula resource when the recipient depends on record data.
Email actions run after save. If your before-save flow needs to trigger an email, split the logic into a before-save flow for the field changes and an after-save flow for the email, or run both in one after-save flow.
Tasks
A Workflow task has an assignee, a subject, a status, and a due date calculated from a trigger date. In a flow, use Create Records for the Task object and set each field explicitly:
Create Records: Task
Subject = "Follow up on " & {!$Record.Name}
WhatId = {!$Record.Id}
OwnerId = {!$Record.OwnerId}
Status = "Not Started"
ActivityDate = {!$Flow.CurrentDate} + 3The mapping rules follow from that:
- The Workflow "Assigned To" setting becomes
OwnerId. A role-based assignment needs a Get Records step to find a user in that role. - "Due date: rule trigger date plus 3 days" becomes
{!$Flow.CurrentDate} + 3. - The related-to object becomes
WhatId. For a Contact or Lead, useWhoIdinstead.
Creating other records
Process Builder's "Create a Record" action maps directly to Create Records. Name the object and set each field. A record that is related to the triggering record needs a lookup field set to {!$Record.Id}.
Process Builder sometimes created several records from one criteria node. In a flow, build a collection variable, add one record variable for each new record, and call Create Records once at the end. A single call uses one DML statement however many records it creates.
Invocable Apex
Process Builder could call an Apex class that has an @InvocableMethod. That same class can be called from a flow's Action element, and it appears in the Action list under the label you gave it. You do not rewrite the class. You map each input to a value in the flow.
The method receives a list of requests, one per record that triggered the flow in the batch, so it must already handle many records at a time:
public with sharing class ClosedWonReview {
public class Request {
@InvocableVariable(required=true)
public Id opportunityId;
@InvocableVariable
public String note;
}
@InvocableMethod(label='Create Closed Won Review Task')
public static void createTasks(List<Request> requests) {
List<Task> tasks = new List<Task>();
for (Request r : requests) {
tasks.add(new Task(
Subject = 'Closed won review',
WhatId = r.opportunityId,
Description = r.note
));
}
insert tasks;
}
}In the flow, place the Action element after the entry condition. Set opportunityId to {!$Record.Id}. Check that the class has no assumption of a single record. A method that reads requests[0] only will miss records once the flow runs in bulk.
Review checklist for each translated action
- Confirm whether the action touches only
$Record. If so, try a before-save flow. - Confirm each Update Records, Create Records, and Action element sits outside any loop.
- Check every picklist formula for
TEXT(). - Check that email and task recipients still match the original.
- Run the flow against the old tool's expected result in a sandbox before disabling the old automation.
Exercise
A Process Builder process creates a Task and updates the parent Account's Rating when an Opportunity becomes Closed Won. Which save context does the flow need, and why? Name the elements you would use.
Show answer
It needs an after-save flow, because it creates a Task and updates a record other than the triggering one, and a before-save flow can only change the triggering record. Use Create Records for the Task, with WhatId set to the Opportunity Id, and Update Records on the Account reached through {!$Record.Account.Id} (or Get Records, then Update Records). Neither element goes inside a loop.