Blog

How to fire a trigger for existing records in Salesforce using Flows

So you’ve just deployed a new trigger or flow and you want to push your org’s existing records through it. This can often be referred to as a “Mass Touch” or “Mass Update”. There are many different ways that this can be achieved, some involving exporting data using third-party tools, but here’s one approach that can be done completely within Salesforce, and with no code!

Create a new “Mass Touch” field

We’ll start the process by adding a new field on the object we want to fire the trigger on. This field will be used to update the record without touching its existing data.

  • Go to Salesforce Setup.
  • Select Object Manager.
  • Locate the object you want to execute a mass touch for and select it.
  • Go to Fields & Relationships.
  • Select New.
  • Data Type: Number.
  • Press Next.
  • Field Label: Mass Touch
  • Length: 1
  • Decimal Places: 0
  • Field Name: MassTouch
  • Help Text: This field should only be used to invoke an update on the record and should not be populated by user entry.
  • Press Next.
  • Only provide visibility to your profile (or the profile of the user completing this process).
  • Press Next.
  • Uncheck Add Field to prevent the field from being added to the page layout.
  • Select Save.

Your object now has a new field that can be updated without impacting existing business data.

Creating a scheduled flow

We now need to create a flow that’s going to look at all the records on the object and update the Mass Touch field just created. We’re going to do this using a Scheduled Flow as this will allow us to set a time for the process to fire. If your object has a lot of existing records it may be preferable to run this process out of hours.

  • Go to Salesforce Setup.
  • Search for Flows in the left navigation and select Flows.
  • Select New Flow.
  • Choose Schedule-Trigger Flow and select Create.
  • Select Set Schedule.
  • Choose a Start Date and Start Time that work for your org.
  • Set Frequency as Once.
  • Select Done.
  • There is no requirement to specify an object in the start element so leave this empty.

The start element in the flow is now configured. Let’s follow that up and add an Update Records element.

  • Press the + icon to open the Add Element view.
  • Scroll down to Data and select Update Records.
  • Label: Update Records
  • API Name: UpdateRecords
  • Description: Set the records' Mass Touch field to a new value.
  • How to Find Records to Update and Set Their Values: Specify conditions to identify records, and set fields individually.
  • Under Update Record of This Object Type, search and select the Object you want to perform the mass touch on.
  • Under Filter Object Records, you can add conditions to only mass touch a selection of records, or have this set to “None” which will update all. We’ll use None for this example.
  • Under Set Field Values for the Object Records, choose the Mass Touch (MassTouch__c) field.
  • Value: 1. (If you’re running the mass touch on this object again in the future you can change this value to 2, or 3 and keep cycling the number for each mass touch you want to complete, it just needs to change from its previous value).
  • Select Done.

With the flow configured, we now need to save it and name it.

  • Select Save from the top right.
  • Provide a Name and Description for the flow so that you will be able to identify it in the future should you wish to run it again.

Validation rule management

Before running a mass touch job on the object we need to consider validation rules. Flows do not have an elegant way to bypass validation rules so keep an eye out for any flow errors when the job runs. An email will be sent to your own user account’s email address containing the errors faced during the flow allowing you to manually correct the conflicting errors (see image below).

If there are some common offending validation rules consider disabling them temporarily to complete this task but remember to re-enable them when you’re done!

Run the flow

The flow is now fully configured and ready to be activated. Use the Activate button in the top right to enable the flow. The mass touch operation will begin when the scheduled time configured in the Start element is met.

If you don’t want to wait for the scheduled time you can run the flow immediately by selecting Debug. Make sure that you uncheck “Run flow in rollback mode” to ensure that the mass touch’s changes persist after the flow has been executed.

Remember, check your emails after the flow has run to review any errors as the update can roll back multiple records even if a single record fails.

Summary

We hope that you have found this article to be helpful for your organization and just a reminder to be vigilant when running mass update operations in a production environment, where possible backup your data first.

If you’d like to find out more about what ProvenWorks do, check out our homepage.

Leave a Reply