I am thinking of a way to bypass triggers from both Flow and Apex when I execute the DML statements on my batch class.
Framework setup:
I have a Hierarchy Custom Setting that has checkbox fields per Object.
Apex Trigger Handler:
public class AccountTriggerHandler implements TriggerHandler {
public Boolean isDisabled() {
return !Trigger_Setting__c.getInstance().Account__c;
}
// trigger code
}
On the Flow, the Hierarchy Custom Setting is retrieved at the first node.
I was optimistic that because of the cached nature of custom settings that it will be a simple assignment of the Trigger Setting to false before the DML then revert back to true after the DML. Unfortunately, it does not work this way and I have to do a update operation on the custom setting for this to work.
Trigger_Setting__c triggerSetting = Trigger_Setting__c.getInstance();
triggerSetting.Account__c = false;
update triggerSetting;
update accounts;
triggerSetting.Account__c = true;
update triggerSetting;
I think this should have no issues on other users ability to run automations because I have set up the hierarchy custom setting on user level and should not affect other users when an Account operation is made during the batch job execution - there is a dedicated user that will run the scheduled batch job.
Just want to know the community's thoughts if there is a better way to do this.