Sub topic 4
Reading current and prior values with $Record and $Record__Prior
This chapter assumes you know how to configure a record-triggered flow (object, trigger event, entry conditions) and can build basic formulas. It covers the two global variables that give a flow access to the triggering record, and the errors people hit when using them.
The two record variables
Every record-triggered flow gets two variables without you creating them.
{!$Record}holds the triggering record with its values as they are in the current transaction. In a before-save flow, this includes changes made by the user or by earlier automation that ran before your flow.{!$Record__Prior}holds the values the record had before the update started. It exists only when the flow runs on an update. On a create, there is no prior record, so every field in it is empty. On a delete trigger, only$Recordis available.
Use $Record to read what the record looks like now. Use $Record__Prior to find out what changed.
| Trigger event | `$Record` | `$Record__Prior` |
|---|---|---|
| Created | New values | Empty |
| Updated | New values | Values before the update |
| Deleted | Values being deleted | Not available |
Comparing current and prior values
The most common use is detecting a change. You can compare the two variables directly in a Decision element or in an entry condition formula.
AND(
{!$Record.StageName} = "Closed Won",
{!$Record__Prior.StageName} <> "Closed Won"
)This is true only when the stage became Closed Won in this save. It stays false when the record was already Closed Won and someone edited another field.
You can also use the ISCHANGED function, which does the same comparison for you:
AND(
ISCHANGED({!$Record.StageName}),
{!$Record.StageName} = "Closed Won"
)Both forms work as a Formula Evaluates to True entry condition. ISCHANGED is shorter. Direct comparison with $Record__Prior is more flexible, for example when you need to test the old value against a list or compare two different fields.
flowchart TD
A[User saves Opportunity] --> B{Trigger event}
B -->|Created| C[Only $Record has values]
B -->|Updated| D[$Record has new values]
D --> E[$Record__Prior has old values]
E --> F{Values differ?}
F -->|Yes| G[Flow logic runs]
F -->|No| H[Flow does not enter]Using $Record in each flow type
In a before-save flow, you change $Record directly with an Assignment element. The platform saves those values as part of the original save, so no Update Records element is needed.
Assignment element
Variable: {!$Record.NextStep}
Operator: Equals
Value: Review large dealIn an after-save flow, $Record is already saved, so {!$Record.Id} has a value even on create. This lets you point related records back at the triggering record.
Create Records element (object: Task)
Subject: Send welcome package
WhatId: {!$Record.Id}
OwnerId: {!$Record.OwnerId}An after-save flow cannot change $Record with an Assignment alone. To change the triggering record there, you use an Update Records element, which performs extra DML. That is the main reason to prefer before-save for same-record field updates.
Common errors
- Using
$Record__Prioron create. Its fields are empty, so a condition like{!$Record__Prior.StageName} <> "Closed Won"is true for every new record. If the flow also triggers on create, test the create case on purpose. - Expecting
$Record__Prioron delete. It is not available. Use$Recordto read the values being deleted. - Assuming
$Record__Priorreflects earlier flows. It holds the values from before the whole save began, not before your flow. If another before-save flow already changed a field,$Recordshows the new value and$Record__Priorstill shows the original. - Reading
{!$Record.Id}in a before-save create. The record has no Id yet. Use an after-save flow if you need it. - Writing to
$Record__Prior. It is read-only. Assign values to$Recordinstead.
Exercise
A flow triggers on "A record is created or updated" for Opportunity. Its entry condition is {!$Record__Prior.StageName} <> "Closed Won" and {!$Record.StageName} = "Closed Won". A user creates a new Opportunity with the stage already set to Closed Won. Does the flow run, and why?
Show answer
Yes. On create, $Record__Prior is empty, so $Record__Prior.StageName <> "Closed Won" is true, and the current stage is Closed Won. Both parts pass. If you want to run only on a real change, set the trigger to updates only or add a check that the prior value is not blank.