Prior Value of a Record in Record-Triggered Flows

Prior Value of a Record in Record-Triggered Flows

Last Updated on February 10, 2022 by Rakesh Gupta

To understand how to solve the same business use case using Process Builder. Check out this article Getting Started with Process Builder – Part 53 (Field history tracking for Multi-Select Picklist).

Big Idea or Enduring Question:

  • How do you track what has been changed on a Multi-Select picklist? 

Tracking field history is an out-of-the-box feature to track value changes in a field. You can select certain fields to track and display the field history in the History related list of an object. The field history data is retained for up to 18 months. Note that the Long text area, Rich text area, and Multi-select Picklist fields are tracked as edited, but their old and new field values are not captured when the record is updated. History tracking capture the following information:

  • Prior value 
  • Current value
  • Who has done the changes
  • When it was changed


After reading this blog, you’ll be able to: 

  • Understand how to track field value changes for Multi-select picklist
  • Use After-save Record-Triggered Flow to create a record
  • Access the prior value of a record in the record-triggered flow

Business Use Case

Pamela Kline is working as a System administrator at Universal Containers (UC). She has received a requirement to enable field history tracking for multi-select picklist (Country) on the Lead object, also capture country old and new values.

Country - Multi-select picklist

Automation Champion Approach (I-do):

There are multiple ways to solve the above business requirement. You can either use Apex trigger, Salesforce Flow, Process Builder, and more. To solve this requirement, we will use the After-save Record-Triggered Flow

Salesforce now (After Spring’21 Release) allows you to add access to the PRIOR Value of a record in the Salesforce Flow, similar to the Process Builder. This is a major enhancement that will ultimately bring Flow to the next level. 

After selecting the object Salesforce will automatically create a record variable ($Record__Prior) of the type selected object. Now you can refer to it anywhere in the flow. 

Before diving further, let me show you a diagram of a Process Flow at a high level. Please spend a few minutes to go through the following Flow diagram and understand it. Let’s begin building this automation process.

Guided Practice (We-do):

There are 3 steps to solve Pamela’s business requirement using Process Builder. We must:

  1. Create a Multi-select picklist
  2. Create a custom object that will be used to store old and new values of the multi-select picklist 
  3. Salesforce Flow
    1. Define flow properties for record-triggered flow
    2. Add a decision element to verify if the country multi-select field is changed
    3. Add a create records element to insert a record in the custom object 

Step 1: Creating a Custom Multi-select Picklist Country on Lead Object 

On the Opportunity object, create a lookup field called Opportunity Approver as mentioned in the steps below. 

  1. Click Setup.
  2. In the Object Manager, type Lead.
  3. Select Fields & Relationships, then click New.
  4. Select Picklist (Multi-select) as Data Type, then click Next.
  5. Enter Field Label and click the Next button. The API Name will populate. 
  6. As a best practice, always input a description
  7. Set the Field-level Security for the profiles, make sure to grant field access profiles. 
  8. Add this field to Page Layout.
  9. Click Save.

Step 2: Create a Custom Object 

The next step is to create a custom object Country History Tracking and a few custom fields to store related information which will use to use old and new values of country multi-picklist. 

  1. Click Setup.
  2. In the Object Manager, click Create | Custom Object.
  3. Now create a custom object Country History Tracking and fields as shown in the screenshot below: 
  4. Click Save.
  5. Set the object security and setting as mentioned below: 
    1. Organization-Wide Defaults: – Public Read Only
    2. Field-level Security: – View
    3. Object-level Permission: – Read
    4. Remove Edit and Del button from the page layout

Step 3.1: Salesforce Flow – Define Flow Properties 

  1. Click Setup.
  2. In the Quick Find box, type Flows.
  3. Select Flows then click on the New Flow.
  4. Select the Record-Triggered Flow option and click on Next and configure the flow as follows: 
    1. How do you want to start building: Freeform
    2. Trigger the Flow When: A record is created or updated 
    3. Run Flow: After the record is saved
    4. Object: Lead
    5. Set Conditions: None
  5. Click Done.

Step 3.2: Salesforce Flow – Using Decision Element to Compare Current and Prior Value of Country Multi-select Picklist 

Now we will use the Decision element to compare the old and new values of the country multi-select picklist. If both the values are not the same means it is changed. 

  1. Under Toolbox, select Element
  2. Drag-and-drop Decision element onto the Flow designer. 
  3. Enter a name in the Label field; the API Name will auto-populate.
  4. Under Outcome Details, enter the Label the API Name will auto-populate.
  5. Condition Requirements to Execute OutcomeAll Conditions Are Met (AND)
    1. Row 1:
      1. Resource: {!$Record.rakeshistomMVP__Country__c}
      2. Operator: Does Not Equal 
      3. Value: {!$Record__Prior.rakeshistomMVP__Country__c}
  6. When to Execute Outcome: If the condition requirements are met
  7. Click Done.

Step 3.3 Salesforce Flow – Add a Create Records Element to Insert a Record Into Country History Tracking Custom Object 

 The next step is to capture the old and new values for the country multi-select picklist in the custom object for this we will use the Create Records element.

  1. Under Toolbox, select Elements. Drag and drop Create Records onto the canvas. 
  2. Input the following information:
    1. Enter Label the API Name will auto-populate.
    2. How Many Records to Create: One
    3. How to Set the Record Fields: Use separate resources, and literal values
    4. Object: Country_History_Tracking__c
    5. Set Field Values for the Country History Tracking
    6. Row 1:
      1. Field: OwnerId
      2. Value: {!$User.Id}
    7. Click Add Row
    8. Row 2:
      1. Field: Action__c
      2. Value: Changed from {!$Record__Prior.rakeshistomMVP__Country__c} to {!$Record.rakeshistomMVP__Country__c}
    9. Click Add Row
    10. Row 3:
      1. Field: Changed_By__c
      2. Value: {!$User.Id}
    11. Click Add Row
    12. Row 4:
      1. Field: Chnaged_Date_Time__c
      2. Value: {!$Flow.CurrentDateTime}
    13. Click Add Row
    14. Row 5:
      1. Field: Lead__c
      2. Value: {!$Record.Id}
  3. Click Done.

In the end, Pamela’s Process will look like the following screenshot:

Once everything looks good, perform the steps below: 

  1. Click Save.
  2. Enter Flow Label the API Name will auto-populate.
  3. Click Show Advanced.
  4. API Version for Running the Flow: 51
  5. Interview Label: Prior Value Examples – Spring21 {!$Flow.CurrentDateTime}
  6. Click Save.

Almost there! Once everything looks good, click the Activate button. 

Proof of Concept

Formative Assessment:

I want to hear from you!  

What is one thing you learned from this post? How do you envision applying this new knowledge in the real world? 

Let me know by Tweeting me at @automationchamp, or find me on LinkedIn.

Have feedback, suggestions for posts, or need more information about Salesforce online training offered by me? Say hello, and leave a message!

5 thoughts on “Prior Value of a Record in Record-Triggered Flows

  1. I keep getting DML error. Is there a workaround for this?

    Error Occurred: This error occurred when the flow tried to create records: MIXED_DML_OPERATION: DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): User_Log__c, original object: User. You can look up ExceptionCode values in the SOAP API Developer Guide.

  2. Hi Rakesh,
    Nice Post.However,In my developer org I could not find $Record__prior feature.Has it been made available to all by Salesforce?

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.