We know that we cannot update the code in Production. Sometimes we are stuck in a situation where we need to stop the triggers. For that we need to deploy the trigger again from pre-prod environment to Prod Environment with the required modification.
To overcome this long process, we can use switch on/switch off framework.
Lets us see how.
- Create a list custom settings, lets say Trigger_Switch__c
- Create a Boolean field called Active__c
- Create a record in the custom setting with Name as per your choice(I will keep it Method1) and make Active__c as True and Save it.
- Now open a trigger and write below code.
trigger AccountTrigger on Account (<events>) {
Map<String,Trigger_Switch__c> mapTriggerSwitch = Trigger_Switch__c.getAll();
if(mapTriggerSwitch .containsKey('Method1')
&& mapTriggerSwitch .get('Method1').Core_Active__c){
accountCtrl.Method1(trigger.new);
}
}
This code will check whether the custom setting record is active or not. If it is active then the method will be called else not.
Please share the blog and leave a comment about your thoughts.
Click here for more blogs.