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?– EricSSHCommented Dec 8, 2016 at 16:11
-
1Did 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.cordCommented Dec 8, 2016 at 16:14
1 Answer
You have two options:
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.
-
-
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– EricCommented Dec 8, 2016 at 15:58