A comment came in on last week’s post about Batch Apex and modern async patterns. Someone studying for PD1 asked whether Queueable circuit breakers work like trigger recursion guards. The analogy was sharp. However, the underlying question pointed to something more fundamental.
Why do governor limits reset at all between async contexts? What exactly constitutes a transaction boundary in Salesforce? And how should architects design systems with those boundaries in mind?
Those questions deserve a full answer. That is what this post is about.
What an Apex Transaction Actually Is
Most developers learn that governor limits reset between transactions. Fewer stop to think about what a transaction actually represents at the platform level.
An Apex transaction is a complete unit of work. It begins when an execution context starts and ends when that context finishes, either successfully or with an unhandled exception. Every operation inside that boundary, SOQL queries, DML statements, callouts, CPU consumption, shares the same governor limit pool.
Critically, Salesforce calculates transactional limits based on a concept of execution context. This is not exclusive to executions of custom code within a single org. Execution context is based on the platform runtime engine, and all code available to that runtime engine for a particular tenant contributes. That includes installed package code, platform service code, and your custom logic running together.
Furthermore, a transaction begins when the Apex request starts and ends when it completes or encounters an unhandled exception. If an unhandled exception occurs, Salesforce automatically rolls back all database operations in the transaction. There is no partial commit by default. Everything succeeds or nothing does.
This all-or-nothing behaviour is foundational. It is also where most architectural mistakes originate.
Synchronous vs Asynchronous: Two Different Allowances
The distinction between synchronous and asynchronous execution is not just about timing. It directly determines the resource budget your code receives.
Synchronous Apex runs in real time, meaning the user waits for the response. Asynchronous Apex runs in the background, meaning the user does not wait. SOQL queries are limited to 100 in a synchronous context and 200 in an asynchronous one. CPU time is capped at 10 seconds synchronously and 60 seconds asynchronously. Heap size follows the same pattern: 6 MB synchronously versus 12 MB asynchronously.
These are not arbitrary numbers. Salesforce allocates higher limits to async contexts because the platform expects heavier workloads there. Synchronous contexts must stay lean to preserve a responsive user experience. Async contexts, by contrast, are designed for bulk and integration work that can tolerate background execution.
This is also why moving a complex operation from a trigger into a Queueable job is not merely a pattern preference. It is an architectural decision about which resource budget your code deserves.
The Static Variable Trap
One consequence of transaction isolation that catches even experienced developers is static variable scope. Static variables persist for the lifetime of a transaction, not the lifetime of a job chain.
Consider a Queueable class that uses a static Boolean to track whether a certain operation has already run. When that Queueable re-enqueues itself, the next execution is a brand new transaction. Accordingly, all static variables reset to their default values. The flag your previous execution set is simply gone.
This is the core distinction from trigger recursion guards. A static Boolean bypass in a trigger framework works because the trigger and everything it calls share the same transaction. The flag persists for the duration of that context. In contrast, chained Queueable jobs are isolated transactions. Each one starts completely fresh.
How Batch Apex Uses Transaction Boundaries
Batch Apex is built around transaction isolation by design. Understanding this makes its behaviour far more predictable.
For Batch Apex, governor limits are reset for each batch of records in the execute method. The start method runs in its own transaction. Each execute chunk runs in a separate transaction with its own full governor limit allowance. The finish method runs in yet another transaction.
This is precisely why Batch Apex can process millions of records. No single transaction bears the load of the entire dataset. Instead, the platform distributes the work across many isolated transactions, each with a fresh limit pool.
However, this architecture also creates a data isolation challenge. Because each execute chunk is independent, a rollback in chunk five has no effect on chunks one through four. Those completed successfully in their own transactions.
Savepoints only work in the current transaction. So if you execute a batch job that requires ten batches to process all the records, rolling back batch ten has no effect on batches one through nine, as those took place in their own transactions which completed successfully.
For architects, this means Batch Apex is appropriate when partial success is acceptable or when each chunk is independently valid. It is a poor choice when the entire dataset must succeed atomically as a single unit of work.
Queueable Chains and the Isolation Problem
Queueable Apex follows the same transaction isolation model, but the implications scale differently because of chaining.
Each Queueable runs in a separate transaction from the initiating context, meaning async code receives a fresh governor limit pool with no shared ceiling from the caller. Crucially, however, that isolation comes with a trade-off: execution order is never guaranteed.
That final point carries significant architectural weight. When you enqueue a Queueable from a trigger, the trigger transaction and the Queueable transaction are completely isolated. The Queueable may execute seconds or minutes later, depending on platform load. Moreover, it receives no knowledge of what the trigger transaction contained beyond what you explicitly pass through the constructor.
This is the real answer to the circuit breaker question from last week’s comment. A Queueable depth counter works not because it shares state with a previous transaction, but because you explicitly pass that counter through the constructor into each new transaction. The counter is not a static variable. It is a serialised piece of state carried forward by design.
If you are in a Queueable job context, you can enqueue only one additional Queueable job. The total number of Apex jobs in the queue is limited to 250,000 per 24 hours, including all types of asynchronous jobs such as future, Queueable, Batch, and Scheduled jobs.
Consequently, unbounded chaining is not just a theoretical risk. It is a platform constraint that requires intentional design. Every chained job must carry its own termination logic.
Savepoints and What They Cannot Do Across Boundaries
Savepoints are one of the most underused and misunderstood tools in Apex transaction management. They allow partial rollback within a single transaction, which is valuable for complex multi-step DML operations.
However, savepoints are strictly scoped to the current transaction. They offer no mechanism to coordinate rollback across multiple async executions. Therefore, any architecture that requires cross-transaction atomicity must handle failure at the orchestration layer, not the transaction layer.
A practical pattern for this is state tracking via a custom object or Platform Cache. Each async job writes its completion status before re-enqueuing the next step. If a job fails, a monitoring process can identify incomplete chains and trigger compensating logic. This is the async equivalent of a saga pattern in distributed systems.
The key takeaway is that you cannot rely on the platform to undo work across transaction boundaries. That responsibility belongs to your architecture.
Limit Reset in Practice: A Reference
| Context | SOQL Queries | DML Statements | CPU Time | Heap Size |
|---|---|---|---|---|
| Synchronous (trigger, VF) | 100 | 150 | 10 seconds | 6 MB |
| Asynchronous (Queueable, future) | 200 | 150 | 60 seconds | 12 MB |
| Batch execute chunk | 200 | 150 | 60 seconds | 12 MB |
| Batch start / finish | 200 | 150 | 60 seconds | 12 MB |
| Scheduled Apex | 100 | 150 | 10 seconds | 6 MB |
Note that Scheduled Apex applies synchronous limits despite being a background job. This surprises many developers and architects encountering it for the first time.
Architectural Implications for System Design
Understanding Apex transaction boundaries reframes several common design decisions.
Triggers should be thin. A trigger’s synchronous transaction is the most constrained context on the platform. Heavy logic belongs in async contexts. Furthermore, any logic that calls out to external systems must move to a Queueable or future method, since callouts are prohibited after DML in a synchronous context.
Failure tolerance must be explicit. Because async transactions are isolated, there is no automatic compensation when a chained job fails mid-sequence. Architects must design explicit retry logic, status tracking, and alerting at the orchestration layer. A Custom Metadata flag or a lightweight status object is a reasonable foundation for this.
State must travel with the job. Since static variables reset between transactions, any state that a chained Queueable needs must be serialised into its constructor. This includes counters, record ID lists, processing offsets, and any flags that influence control flow.
Partial success is sometimes correct. Batch Apex’s transaction-per-chunk model is a feature, not a limitation, when the use case allows independent processing. Migrating records, recalculating rollup fields, or syncing data to external systems are all cases where partial progress is preferable to an all-or-nothing failure.
Platform Events cross transaction boundaries cleanly. Publishing a Platform Event commits to the event bus regardless of what happens to the publishing transaction’s other DML. This makes Platform Events an effective pattern for triggering downstream async work without coupling it to the original transaction’s success or failure.
Best Practices for Apex Transaction Boundary Design
Make state explicit, never implicit. If a chained Queueable needs to know something about its predecessor, pass that information through the constructor. Never assume static state will persist.
Design for partial failure. When building multi-step async pipelines, assume that any step can fail independently. Build compensating logic and status tracking from the start.
Use savepoints defensively within a transaction. For complex multi-step DML inside a single context, savepoints provide a controlled rollback mechanism. However, use them sparingly. Overly complex savepoint logic is difficult to reason about and harder to test.
Monitor your org-wide async limits. The 250,000-job-per-day limit spans all async types. High-volume orgs with multiple Batch jobs, Scheduled Apex, and Queueable chains can approach this ceiling faster than expected. Build monitoring into any system that generates async jobs at scale.
Treat Scheduled Apex as synchronous. Many developers design Scheduled Apex classes with async-level limit assumptions. That assumption is wrong. Scheduled Apex runs under synchronous governor limits. Move heavy processing into a Batch or Queueable job invoked from the Schedulable class instead.
Conclusion
Governor limits resetting between async contexts is not a quirk. It is the direct result of how Salesforce models execution contexts in a multitenant architecture.
Every Apex transaction is an isolated unit of work. Each async context starts fresh. Static variables, savepoints, and DML state do not cross transaction boundaries. Architects who design with this model in mind build systems that scale predictably. Those who work against it eventually discover its constraints at the worst possible moment.
The question from last week’s comment was insightful. Trigger bypass flags and Queueable circuit breakers solve similar problems: preventing runaway execution. However, one operates within a transaction and the other must be designed to survive across many of them.
That difference is everything.
Key Takeaways
- An Apex transaction is a complete unit of work sharing a single governor limit pool
- Async contexts receive higher limits: 200 SOQL, 60 seconds CPU, 12 MB heap
- Batch Apex resets limits for every execute chunk, start, and finish method independently
- Static variables reset between chained Queueable transactions; state must be passed explicitly via constructors
- Savepoints only operate within the current transaction and cannot coordinate cross-transaction rollback
- Scheduled Apex applies synchronous limits despite running in the background
- Platform Events cross transaction boundaries cleanly, making them ideal for async orchestration triggers
- The 250,000 async job daily limit spans all job types and requires org-level monitoring in high-volume implementations
Read More!
Is Batch Apex Dead? Why Database.getCursor(), Queueable, and Event-Driven Design Are Changing Async Processing in Salesforce
Apex Governor Limits
Leave a Reply