Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

For example, If I have a bunch triggers that aren't bulkified, so I'll end up hitting the governing limits were to do 100 insert opportunities in an separate apex class.

For batch apex, if I were to do an insert on opportunities, I assume it will fire those triggers and if the same governing limit apply?


share|improve this question
up vote 9 down vote accepted

Yes, triggers will fire when the Batch Apex runs and if you have large numbers of records in your batch you will hit the governor limit.

One solution would be to set the batch size to 1 so that every time the triggers fire there will only be 1 record. The batch class can be started with a batch size of one using something like this:

Id batchInstanceId = Database.executeBatch(new MyBatchClass(), 1); 

Another solution, and probably the best one, is to bulkify your triggers.

share|improve this answer

A third solution is to consider if you don't need the trigger processing to occur, in addition to BarCotter's good suggestions, is to set a static boolean variable that your triggers could use to avoid trigger processing.

public static boolean isRunningBatch;

Set to true at the start of your execute method and then in your triggers:

if (!isRunningBatch) { //run trigger code }

This only makes sense if you don't need the trigger logic during the batch however.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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