Replace Simple Triggers With Before-Save Flows

Updated 15/09/2022

The first triggers I learned were simple things for example updating a field based on something else being filled out. Before record triggered flows this wasn’t possible to do in an efficient manner. You used to have to use a process builder to trigger an auto-launched flow which depending on what else was going on in terms of automation could feel slow to save.

So what we are going to use is one of the trigger examples from Salesforce Trailhead which I’ve included below. To see full Get Started with Apex Triggers on trailhead click here

trigger HelloWorldTrigger on Account (before insert) {
    for(Account a : Trigger.New) {
        a.Description = 'New description';
    }   
}

Replacement Flow

Setting The Flow

So just a quick run-through of what is happening here. before inserting means before the record is created. So it is inserting the words ‘New description’ into the description field on an account. Pretty straightforward forward it’s essentially a record-setter function so we will go through doing this in Flow builder.

  1. Create Record Triggered Flow.
  2. Set Object To Account.
  3. Set To When Created.
  4. Select Fast Field Updates.
Setting the record triggered flow trigger point. Setting To Fast Field Updates makes it a Before-Save Flow
Configuring Start as described above

So now we have basically created the trigger to trigger at the same point as the above example.

Updating The Record

  1. Created Update Records Element
  2. Set Description as the field
  3. Type in the value ‘New description’
  4. Click done on the screen.
Screenshot of setting the record update to replicate simple trigger
Setting The Update Fields

Activating and Testing

Now that has been done all that you need to do is save the flow and activate it. Your flow should look like the below image. Go ahead and test it out a few times creating some accounts.

What the flow looks like when complete.

If you want to update other records or create records or make actions like sending email alerts out you will need to have to change Fast Field Updates to Actions and Related Records check out this guide on creating an after-save flow. You can find more examples of this in my tutorial section here.

Published 03/09/2022
Category: Beginner Friendly, Migration, Tutorials
Tags: , ,

Other Posts