You need to sign in to do that
Don't have an account?
SrikanthKuruva
Batch Apex and Triggers
HI,
I just got this doubt. Say we have batch apex which is updating accounts and we have a before update trigger on accounts. In this scenario how are the governor limits considered?
Each iteration of the batch operates in it's own context - so if you update 200 records per batch execution (the default), you should be fine so long as you followed best practices in building triggers that work in bulk.
i agree that triggers should be bulkified, but i what i am looking at is that the
SOQL queries for batch apex is 200 and
SOQL queries for triggers is 100
so say the triggers are firing after batch apex (say for the first batch i.e. 200 records) so then how are the governor limits considered?
If some code is fired as part of a trigger, the 100 limit will apply to that set of records being processed...
in that case if the trigger fails, will the batch apex fail?
Looking at the new Winter 12 release notes, I noticed that there are some new checks for isBatch, isFuture and isSchedule...
So I am wondering if a trigger fired from a batch does get to use 200 SOQL queries, but a trigger fired via the UI/API is still restricted to 100 queries, but unless you could ensure a trigger only fired due to a batch operation, you would need to use these new checks to make sure you only utlized 200 queries when it was invoked from a batch...
But that's just a guess at this stage...