Lightning Flow: How to Start and End a Before-Save Flow

Hmmm… Before-save updates in Flow?!
Very interesting, Dr Jones…

In the Spring ’20 release, Salesforce introduced a game changer to Lightning Flow – before-save updates! Before-save updates in flows are much faster than other available record-triggered updates. For example, a before-save update in a flow is 10x faster than an update in a record-change process that’s built in Process Builder.

Salesforce recommends using a before-save flow because of their speed. It is recommended that you use before-save updates in flows to update fields on new or changed records because you can even avoid the limit for maximum CPU time on the Salesforce servers. These new flows can replace Apex code and record-change process builders.

If you’re like me, I like to get my hands on a new tool before fully reading the instructions (much to my wife’s chagrin). When I tried to build my first before-save flow, it took me about 12 minutes and, ultimately reading the instructions, to understand how to change the initiation point of the flow to execute before save.

How to Start a Before-Save Flow

To enable the before-save functionality in a flow, the first thing you need to do is double-click the start component. This will open the config window which allows you to change how the flow is initiated. You have to choose the New or updated records – flow makes fast field updates option in the “What Launches the Flow” section (as shown in the image below).

Choose the second option in the “What Launches the Flow” section of the Start component to become a Before-Save flow.

You’ll notice the options in the Toolbox drastically reduce. That’s because you can only make edits to this singular record in this type of flow. I recommend trying to make your flow launch before a save so you can optimize the processing time in your org. There is a chance you cannot accomplish the goal with a before-save flow, but it is worth the extra effort to attempt it this way first.

The Toolbox reduces available elements when it changes to a before-save flow.

I was trying to figure out how Lightning works… then it struck me.

Salesforce Dad Joke

How to End a Before-Save Flow

In a normal flow, you have to use an Update Records element. In a before-save flow, you don’t get that option. So how do you make the actual update? You use the Assignment element in the flow! The key here is that you have to use the $Record system variable to relate the update back to the original record and appropriate field.

You can update one or every field on the original record and add as many steps as needed to figure out the appropriate values. Don’t shy away from building complex logic to determine how to update the records – just remember that you have a limited tool set available.

Pro Tip: You cannot edit related records with a before-save flow! That needs to occur in a regular flow or a process builder.

Salesforce Dad Life Lesson #154
Salesforce Pap

One more thing…

Remember how I said that before-save flows save CPUs in your org? It might be a good idea to go back and do some housekeeping and see if you can convert any process builders to before-save flows. My dad, Salesforce Pap, always used to say…

Go clean up your mess before your mother finds out and yells at me.

Salesforce Pap