Sub topic 9
Translating actions: field updates, emails, tasks, records, Apex
This chapter assumes you can read a Workflow Rule or Process Builder process, you know basic formula syntax, and you have built a simple record-triggered flow. Here you map each legacy action to the Flow element that replaces it.
The mapping at a glance
Each legacy action has a direct counterpart in a record-triggered flow. The main decision is the save timing. Before-save flows run before the record is written, so they can change the triggering record without a DML statement (a database write). After-save flows can touch other records and call outside services.
| Legacy action | Flow element | Save timing |
|---|---|---|
| Field update on the triggering record | Assignment on `$Record` | Before-save |
| Field update on a related record | Update Records | After-save |
| Email alert | Action: Send Email, or the email alert action | After-save |
| Create a Task | Create Records (Task) | After-save |
| Create a Record | Create Records | After-save |
| Update Records (Process Builder) | Update Records | After-save |
| Invocable Apex or Apex action | Action: Apex | After-save |
| Post to Chatter | Action: Post to Chatter | After-save |
Field updates
For the triggering record, use an Assignment element in a before-save flow. Set {!$Record.Field} to the new value. Do not add an Update Records element. Flow saves the change for you, and a before-save flow is much faster than an after-save one.
For a related record, such as the parent Account, use Update Records in an after-save flow. Pick the record by its relationship, for example {!$Record.AccountId}, and set the fields you need.
Emails and tasks
Reuse your existing email alerts. Add an Action element, choose the email alert, and pass the record Id. Templates and recipients stay unchanged.
Workflow Task actions become Create Records on the Task object. Set WhatId to {!$Record.Id}, OwnerId, Subject, ActivityDate, and Status. A Workflow Task can set a due date relative to a date field. In a flow, compute that date in a formula resource, such as {!$Record.CloseDate} + 7.
Creating and updating other records
Process Builder's Create a Record action becomes Create Records. Copy each field value over, and replace each reference to the process's record with {!$Record}. For Update Records, the "records related to the process" choice becomes a Get Records element or a direct reference through the relationship.
Apex
Process Builder could call an @InvocableMethod. Flow calls the same method through an Action element, so the Apex needs no change. Check two things first. The method must handle a list of inputs, because a flow may batch many records into one call. It must also run correctly after save.
public with sharing class FollowUpService {
@InvocableMethod(label='Create follow-up task')
public static void createTasks(List<Id> oppIds) {
List<Task> tasks = new List<Task>();
for (Id oppId : oppIds) {
tasks.add(new Task(
WhatId = oppId,
Subject = 'Follow up after close',
ActivityDate = Date.today().addDays(7)
));
}
insert tasks;
}
}Exercise
A Process Builder process updates the Opportunity's own Description field and also updates the parent Account's Rating. How would you build this in Flow, and why?
Show answer
Use two flows or two paths by timing. Put the Description change in a before-save flow with an Assignment on $Record, because it only changes the triggering record and needs no DML. Put the Account Rating change in an after-save flow with Update Records, because before-save flows cannot change other records.