One of the great things about Salesforce is the ability to automate tasks. As someone who has been on the platform for a while I’ve used Validation Rules, Workflow Rules, Process Builders, Flow, and Apex Triggers to automate some kind of task. Having all these options is great, but there might be time when I want to manipulate mass records without the automation running. For instance, I might want to bypass sending email notifications to Sales Reps or prevent a validation rule from firing.
There are two methods I use to control automation. The first method prevents the object trigger from firing. The second will bypass specific functionality within Triggers, Flows, and Validation Rules. The second can also be used in Workflow Rules and Process Builders, but we’ve since removed those from our Org.
Method 1: Trigger Kill Switch
I use this method for both Flow Triggers and Apex Triggers. To start, create a custom setting to hold the per object setting. I called mine “Trigger Settings.” Within that object create a boolean field for each object you want to control. For instance, I used “AccountTriggerDisabled.” In your Apex trigger handler check for the value of this boolean at the top of each method. Your Apex handler should have each of these: beforeInsert, afterInsert, beforeUpdate, afterUpdate, beforeDelete, and afterDelete. Only run the logic within the method if the boolean is false. Same with Flows, this would be a top-level decision at the start of the flow. We use three flows to handle Trigger logic per object.
Method 2: Functionality ByPass
To bypass certain functionality, I use a boolean field within the object simply called “ByPassLogic.” The default value for this field is false. When I want to bypass logic, I set the value to true. I use this when I want to bypass a Validation Rule, Apex Logic, or Flow Logic. You must remember to set this value back to false in your object trigger handler. I used a Workflow Rule for this in the past, but now I use Apex or Flow depending which of those is handling trigger logic. When using this strategy, keep a log of what is bypassed when the value is true, as you may bypass logic you actually want to fire.
To illustrate a simple case, let’s say we have fields that are required on the Account object when certain conditions are met. This is handled by Validation rules just fine. However, we have an automated process coming from the Order Trigger which updates fields on the Account object. That process could be impeded if the update to the Account were to fail. I adjusted the validation rule to fire only when the bypass flag is set to false. In the update on the Account record from the Order Trigger I set the bypass flag to true. Post update in the Account Apex beforeUpdate trigger, I set the value back to false. This bypass is also be used in an Account Action for power users to set the Account values manually and still take advantage of the override.
Please note, that if you wish to make mass updates and want to bypass triggers AND functionality, you need to include the trigger check in your validation rule OR make sure your triggers do not bypass the RESET of the bypass flag when disabled.
Conclusion
In conclusion you may want to develop your own strategy on how to bypass automation within Salesforce. I have found the two methods above to meet the needs of our Org. I will advise you to create an Automation dashboard where you keep an eye on records that may not have the bypass flag set to false. Every record should end up in a false state. And finally, I will stress the importance of documentation on what is automated and what is bypassed by which bypass method. I find a matrix per object is very useful.
If you want to develop a strategy to bypass automation in your org and want to bounce around some ideas, feel free to leave a comment.