11

What are the boundaries of the execution context? What are the boundaries of a transaction?

  • 1
    Does this help? help.salesforce.com/apex/… – Boris Bachovski Jun 25 '15 at 23:26
  • @Bachovski Honestly, it doesn't. It only serves to muddy the waters as far as I can tell. – sfdcfox Jun 26 '15 at 0:29
  • can you please add more details & specifics to your question.. it will help the members to understand it from your point of view and answer better. single line questions are tough to understand and might not get answers exactly what you want. – Vamsi Krishna Jun 26 '15 at 1:03
  • That makes it a bit more confusing... so "per-transaction" limits are really "per-context"? That's what that article is saying to me. If so, what are the boundaries of the execution context? – the_rj Jun 26 '15 at 15:49
6

I've come at this from the perspective of when the logging records.

The first and last thing the Apex log records will be EXECUTION_STARTED and EXECUTION_FINISHED respectively.

From Debug Log Details

Execution Units
An execution unit is equivalent to a transaction. It contains everything that occurred within the transaction. The execution is delimited by EXECUTION_STARTED and EXECUTION_FINISHED.

From What's considered an "execution context"? (via Bachovski's comment):

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.

From Apex Transactions

An Apex transaction is sometimes referred to as an execution context. Both terms refer to the same thing. This guide uses the Apex transaction term.

So, each execution context has a corresponding transaction. For all intents and purposes they are one and the same thing.

Limits are applied per Apex Transaction. See Per-Transaction Apex Limits

There are some exceptions for certified managed packages (Aloha Apps?). See Per-Transaction Certified Managed Package Limits

If the overall execution terminates with an exception rather than completing successfully then the transaction will be rolled back. There are finer level DML transaction controls using database savepoints, but the overall execution transaction can still be rolled back for an unhandled exception. See Transaction Control.

| improve this answer | |
  • I appreciate your answer, and I'm wondering this: I was told that an Apex static variable was scoped to the execution context. Is that true? It's value is only reset per context/transaction? Is is set in the transaction, what is its value outside the transaction? – the_rj Jun 30 '15 at 1:25
  • 1
    The static variable will stay in scope for the execution context. This is commonly used for preventing trigger recursion. Different execution contexts will have their own state variables - i.e. you won't get cross talk between the execution contexts via static variables. – Daniel Ballinger Jun 30 '15 at 9:10
2

I'd say that the difference is that a transaction is the event that is happening, while an execution context is the system information associated with that event.

| improve this answer | |

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.