How to bypass the triggers when running batch class update. ACE_MarkEnquiryLostBatch.cls
•16 min read

Below is a clean and safe way to bypass triggers when running a Batch Apex class.
Salesforce does NOT allow disabling triggers directly, but you can bypass them using a static boolean flag inside a utility class or inside the trigger handler.
✅ Step 1 — Create a Trigger Bypass Utility
Create a class that holds a static variable used to disable triggers:
public class TriggerBypassUtil {
public static Boolean bypassTriggers = false;
}
JavaScript✅ Step 2 — Modify Your Trigger Handler to Check the Flag
Inside your trigger handler (recommended) or inside the trigger itself, add:
if (TriggerBypassUtil.bypassTriggers) {
return; // Skip all trigger logic
}
JavaScriptExample:
public class EnquiryTriggerHandler {
public static void onBeforeUpdate(List<Enquiry__c> newList, Map<Id, Enquiry__c> oldMap) {
if (TriggerBypassUtil.bypassTriggers) return;
// Your normal trigger logic here
}
}
JavaScript✅ Step 3 — Call the Batch Class While Setting the Flag
Now in your batch class, set the bypass flag to true before performing updates.
⭐ ACE_MarkEnquiryLostBatch.cls (Example with Trigger Bypass)
public class ACE_MarkEnquiryLostBatch implements Database.Batchable<SObject>, Database.Stateful {
public Database.QueryLocator start(Database.BatchableContext bc) {
return Database.getQueryLocator([
SELECT Id, Status__c
FROM Enquiry__c
WHERE Status__c != 'Lost'
]);
}
public void execute(Database.BatchableContext bc, List<Enquiry__c> scope) {
// BYPASS TRIGGERS BEFORE UPDATE
TriggerBypassUtil.bypassTriggers = true;
for (Enquiry__c enq : scope) {
enq.Status__c = 'Lost';
}
try {
update scope;
} finally {
// Always turn it back off
TriggerBypassUtil.bypassTriggers = false;
}
}
public void finish(Database.BatchableContext bc) {
// Optional post-process
}
}
JavaScript🚀 How it Works
- Batch runs
- Before updating records, we set:
TriggerBypassUtil.bypassTriggers = true; - All triggers that check this flag simply return.
- After updates, flag resets.
🔒 Important Notes
- This method is best practice and Salesforce-safe.
- Works for:
- Batch Apex
- Scheduled Apex
- Anonymous window
- Integration updates
- Never forget to reset the flag in a
finallyblock.
Related Posts

How to Automatically create a follow-up Task when a Lead is converted

How You need to update a related child record whenever a parent record’s status changes, but only if the status is “Closed Won.” How would you design this in Apex?
