Print this page

API Batches are being broken up into batches of 100 when triggers are invoked

Knowledge Article Number 000003793

Static variable values are reset between API batches, but governor limits are not. Do not use static variables to track state information on API batches, because Salesforce may break up a batch into smaller chunks than the batch size you specify.

So essentially what is happening is that a typical (max) API batch is 200 records, but when that batch invokes an Apex trigger, it is split into two batches of 100 which end of running the trigger twice.


This is expected behaviour and generally this would not be a problem, but in the case where you are using static variables to maintain flow control, or are getting close to their gov limits, it can cause problems because the state is maintained between the Apex batches, but reinitialized between the API batches. Given this, you will either need to change your logic to work with this behaviour or set the API batch size to no greater than 100.

promote demote