I don't quite understand when does a transaction ends. I have one class with 10 functions. Each function does approximately 2000 rows inserts or Updates. I have a total DML statements is about 16 SOQL statements for the whole class. I'm very carefully and always do bulk inserts or updates.

So why do I still get "Too Many DML rows" error? Doesn't the transaction end after each insert or update?



The transaction does not end after each insert of update. The Governor Limits count for a so-called execution context. According to the Salesforce documentation this is:

An execution context is the context information available during the lifetime of a transaction. Transactions are requests initiated by users when they update a record in the UI, use the API to upload records, etc.

Governor limits count for each execution contexts (e.g. are reset between execution contexts).

As an example, consider a user that updates an account record, and a trigger is fired which invokes a method in a helper class. This method will have to operate within the governor limits for this transaction, which means that it cannot perform more SOQL queries than the current maximum, etc. Additionally, if the user performs the same operation almost at the same time (for instance by saving two different records in two different browser tabs), each transaction will be considered a separate execution context and will have its own governor limits (e.g. governor limits are not shared across transactions).


In other words: An execution context is all the resulting actions (methods calling each other, triggers etc.) of a request.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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