0

If a batch apex is called with size say 200 (default size). And we have a DML operation (say update) in execute method of the batch. So the trigger which is set to run before/after update will share the same governor limit used in a batch (for a chunk)?

Example:

Each chunk of the batch on execute method runs and updates 200 records (what no. of times is really depends on the record QueryLocator returns).

Then, would after update trigger set for the object only be able to update 9800 record? Since, Salesforce only allow to perform DML up-to 10000 record/transaction and here 200 has been already consumed by the batch for a chunk?

As per my test this is what it is going to happen but I didn't find any clear documentation regarding Trigger behavior after a batch runs, thus wanted to check if my understanding is correct.

2 Answers 2

1

You are correct. Your DML call in the execute() method will count towards the governor limits, and the trigger that is run will only have 9800 DML rows available.

The important thing here is the concept of the transaction. Everything that happens in a single transaction is counted against a single set of governor limits. Same thing happens if you have a trigger that itself performs another DML call.

Once Apex starts running, the only way to get another transaction (i.e. another execution context) and the fresh set of limits it comes with is to call something that runs asynchronously (schedulable, @future, batch, or queueable). There is one other way to get a fresh set of limits, but that's exclusive to unit tests.

2
  • You should mention platform events, which have synchronous limits but behave as if they are async in that a new transaction is started.
    – Phil W
    Commented Jul 6, 2023 at 21:04
  • Thanks, this is just I wanted to confirm if my understanding is correct or not.
    – ItsVicky
    Commented Jul 9, 2023 at 18:38
0

Yes, that is correct. The limit of 10,000 rows is per execution context. This includes the batch and any triggers called by any DML operations.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .