I want to know how to bypass the trigger in Batch apex code.Actually problem is when we are trying to run the batch apex we are facing some errors i think some triggers are firing.Please help me to stop the triggers when batch is running. Please check my below BatchApex class.

  • Why wouldn't you want triggers to run in a batch? – EricSSH Dec 8 '16 at 16:11
  • 1
    Did you remove your code from your post for a reason? You should at least include a self contained example, for answer's to use for reference. – battery.cord Dec 8 '16 at 16:14

You have two options:

  1. To stop triggers from running during ALL batch contacts add

    if(system.isBatch()) return;

to your triggers. NOTE This is the hammer method and will stop any trigger with this from running during ANY batch job.

2. Find out where the errors are and fix them. The issue is not that the batch is running it is that the triggers/code is not written properly

You could also add a static property in the batch you provided and for the problematic trigger check that variable and not run if set to true.

  • please check below bit of code – Siva Dec 8 '16 at 15:56
  • 2
    @Siva - Maybe someone else will be able to help you hack this in. I do not wish to perpetuate the problem by providing an out. You really need to review the code causing the issue and resolve it there. Bypassing the trigger just because it is not working properly is not the best practice. And without knowing your entire instance any direct solution I could provide could have dangerous side effects to the business – Eric Dec 8 '16 at 15:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.