Three ways to stop Trigger in production
- akshay saxena
- Feb 4, 2023
- 2 min read
The pain point is that unlike what you can do in a sandbox, you cannot activate/deactivate a trigger by flipping a checkbox in a production org. Consequently, turning on/off triggers in production org means deploying those triggers with the status being inactive one more time, which could be time consuming as all tests will have to run and pass. Furthermore, when a trigger is turned off, some of your tests may fail. During the go live activity. With any of the three approaches i mentioned below. Just make sure, your overall code coverages is well above 75%.
1.) Deactivate The Trigger:
This is the simplest way to do of all. Deactivate your trigger in your sandbox by unchecking the Active checkbox of the trigger. Create an outbound change set,upload and deploy the change set to production. The trigger in production will be deactivated.
2.) Comment Trigger Code:
Comment your entire apex trigger code or all those functionality that is no longer required in your sandbox and then use outbound change set to deploy to production.
Example:
trigger oppTrigger on opportunity (before insert){ /* your entire code */ }
3.) Custom Setting:
Make use of custom setting using which you can control whether a trigger should run or not. Create a cutsom setting(Trigger_settings__c) Add a checkbox field 'Is Active' . So your custom setting will store the trigger name and its status in Is Active checkbox. Add an IF condition at the top to check if the Trigger status in Custom settings is TRUE, only then run the entire apex trigger code.
Example:
trigger oppTrigger on opportunity (before insert){
Trigger_Settings__c TS = Trigger_Settings__c.getValues('oppTrigger');
if(TS.is_Active__c == TRUE){
//your trigger code
}
}
So, every time you want to turn off the trigger in production, just go to your custom settings and uncheck the IsActive checkbox for that trigger.
Comments