Get Hands-on With Flow Before-Save Trigger When Certain Record Changes are Made

Learning Objectives

After completing this unit, you’ll be able to:

  • Update new and changed records by using before-save updates in flows.
  • Take a flow path only when certain record changes are made.
  • Maintain your Salesforce Certified Platform App Builder certification.

Update New and Changed Records by Using Before-Save Updates in Flows

What’s New?

In Spring ’20, app builders learned that in Flow Builder they can trigger a flow to run before a record is saved. 

Creating or updating a record can now trigger an autolaunched flow to make additional updates to that record before it's saved to the database. Before-save updates in flows are much faster than other available record-triggered updates. For example, a before-save update in a flow is 10 times faster than an update in a record-change process that’s built in Process Builder. Replace your record-change processes with flows to minimize how often the spinner appears when users save records.

To activate a flow that makes before-save updates, an app builder needs the View All Data permission.

Perhaps you’re familiar with Process Builder and using a record-change process to make additional updates to each record that triggers the process. Such a process can set the Region custom field automatically on each new case record. Before-save updates in flows accomplish that same goal, but much more quickly because each record doesn’t get saved to the database again. Avoiding that extra save procedure means skipping another round of assignment rules, auto-response rules, workflow rules, and other customizations that take time to execute.

Perhaps you’re familiar with Apex triggers. A flow that makes before-save updates is similar to a before trigger. The previously described record-change process is similar to an after trigger. In a save procedure, before-save updates in flows are executed immediately prior to Apex before triggers.

Because of their speed, we recommend that you use before-save updates in flows to update fields on new or changed records. You can even avoid the limit for maximum CPU time on the Salesforce servers by replacing Apex code and record-change processes with before-save updates in flows. However, sometimes you need to use a record-change process or an Apex after trigger to:

  • Access field values that are set only after the record is saved, such as the Last Modified Date field or the ID of the new record.
  • Create or update related records.
  • Perform actions other than updating the record that launches the flow.

How Does It Work?

Create a Record-Triggered Flow and Edit the Start element.

New Flow window, with Record-Trigger Flow selected

For Trigger the Flow When, select A Record is created or updated. For Run the Flow, select Before the record is saved.

Configure Trigger with A record is created or updated and Before the record is saved selected.

For a flow that makes before-save updates, the Flow builder toolbox offers only four elements: Assignment, Decision, Loop, and Get Records. These elements let you obtain data from other Salesforce records, and use them to decide whether to update the triggering record’s fields and to what values.

Flow Builder with the Start Record-Triggered Flow element displaying.

The $Record global variable contains the values from the record that triggers the flow to run. As a result, there’s no need to add a Get Records element to obtain the record data nor create flow variables to store the record data. When the flow changes the values in the $Record global variable, Salesforce automatically applies those new values to the record. So there’s no need to add an Update Records element to save the new values to the database.

Take a Flow Path Only When Certain Record Changes Are Made

What’s New?

In Winter ’21, app builders learned that in Flow Builder they could set the path for a flow to filter out unrelated records.

Now you can filter out record updates that are unrelated to your flow’s use case and avoid reprocessing records that previously triggered the flow. A flow that’s triggered by a record update can take different paths if the record that triggered the flow was edited to meet certain criteria. When you configure a Decision outcome, you can now set that outcome to execute only when the triggering record is updated to meet the condition requirements.

This option gives your flows a powerful filtering feature similar to the ISCHANGED function found in Workflow Rules and Process Builder and the oldMap/newMap variables found in Apex. Build more of your automation directly in Flow Builder without requiring Process Builder or Apex to check the prior version of the data.

How Does It Work?

On a record-triggered flow, configure the Start element to trigger when the record is updated, or when it’s created or updated.

The Configure Trigger screen, highlighting trigger options A record is updated, and A record is created or updated

To configure a Decision element’s outcome to only run when the triggering record is updated to match certain conditions, select Only if the record that triggered the flow to run is updated to meet the condition requirements.

The New Decision screen, with the ability to execute an outcome only if the record that triggered the flow to run is updated to meet the condition requirements

Note

Note

This option checks if the triggering record didn't previously meet the criteria and if the $Record variable, not the triggering record, now meets the criteria. If your flow changes any of the $Record variable’s fields before it runs the configured Decision element, the Decision checks if the $Record’s new field values now meet the criteria.

Now that you are all caught up on the release notes for what’s new for Platform App Builders, let’s get hands-on with Flow Builder!

Resources

Keep learning for
free!
Sign up for an account to continue.
What’s in it for you?
  • Get personalized recommendations for your career goals
  • Practice your skills with hands-on challenges and quizzes
  • Track and share your progress with employers
  • Connect to mentorship and career opportunities