Apex, Winter ’27 & Transaction Design
A larger Apex heap is not a licence for larger transactions
More memory changes the ceiling—not the architecture
A nightly integration previously failed near the asynchronous Apex heap limit, so the team celebrates Winter ’27 by increasing the response size and retaining more records in a map. The job now fits, but its memory use grows with customer volume, its callout payload and deserialised object graph coexist in the same transaction, and the next data spike consumes the new capacity. A platform improvement has postponed the failure without removing its cause.
Salesforce’s Winter ’27 release raises the Apex heap limit from 6 MB to 10 MB for synchronous transactions and from 12 MB to 25 MB for asynchronous transactions. That is the verified product change. The JSBC Labs position is that the additional memory should be treated as resilience headroom—not a licence to build larger transactions. Good Apex keeps memory bounded by design so ordinary growth, automation and edge-case records do not turn a successful release into a later production limit failure.
Confirm the runtime limit before relying on it
Salesforce enabled the higher limits automatically according to the Winter ’27 rollout and provided a temporary nonproduction setting for teams deploying into Summer ’26 production during the transition. The release note recommends using Limits.getLimitHeapSize() to confirm the limit available to the running transaction. Current documentation lists 10 MB synchronously and 25 MB asynchronously, but code should not assume an environment from its name or release label.
Add a compatibility check to release testing when sandboxes and production can sit on different release versions. Capture the active limit and peak usage for representative synchronous, Queueable and Batch paths. Do not branch normal business behaviour around a specific number; use the measurement to detect an unexpected environment and to prove that a deployment retains safe margin. A test that merely completes under the new ceiling says nothing about how close it came.
Heap is the shape of the live object graph
Heap pressure is not just the size of the largest List. It is the combined memory held by queried sObjects, maps and sets, wrapper classes, strings, blobs, callout requests and responses, deserialised JSON, error collections and temporary copies created while transforming data. Salesforce documents that callout request and response sizes count toward heap, and that a heap limit exception aborts the transaction and cannot be handled.
Draw the data lifecycle through the method: when each representation is created, when it is last needed and which other representation exists at the same time. A ten-megabyte response can require much more than ten megabytes while it is stored as a string, parsed into objects and converted into records. Reduce simultaneous representations, release references after use and avoid diagnostic logging that reproduces large payloads. The important measure is peak live memory, not input file size.
Query only the data the decision needs
Wide SOQL projections quietly multiply heap use. Retrieving relationship fields, large text, formulas and child collections for every record creates a heavier sObject graph even if later code reads only a fraction of it. Salesforce Well-Architected guidance recommends selecting only required fields and processing large result sets in chunks. That is not micro-optimisation; it is a contract about the information a transaction is allowed to carry.
Start from the output or decision and work backwards to the minimum field set. Split summary and detail queries when only exceptional records need the heavier shape. Be cautious with nested child subqueries because a parent record can bring an unexpectedly large collection into memory. Review field additions to shared selectors as performance changes, and test against skewed parents and maximum text lengths—not only average records.
Stream work instead of accumulating it
Salesforce’s SOQL for-loop mechanism retrieves records in efficient chunks and keeps only a subset of the data in memory. The documentation also explains the trade-off: chunking can consume more CPU, and serialising a partially retrieved parent does not magically include every child record. For mass updates, Salesforce recommends Batch Apex when one transaction should not own the complete result set.
Process a bounded chunk, produce its outcome and discard it before fetching more. Use the list form of a SOQL for loop when DML should operate on groups rather than individual records. For external JSON, consider JSONParser when the payload can be consumed token by token or when large branches can be skipped; avoid deserialising a complete document merely to extract a few values. Streaming is valuable only when later code does not rebuild the entire collection.
Choose asynchronous boundaries for semantics, not megabytes
Moving work to Queueable Apex provides the asynchronous heap ceiling, but it also changes execution time, error handling, monitoring and transaction ownership. Batch Apex goes further by treating every execute scope as a discrete transaction and resetting governor limits for each scope. Salesforce documents the consequence: if one batch succeeds and a later batch fails, earlier commits are not rolled back.
Use Queueable for a bounded unit that belongs in one asynchronous transaction. Use Batch when the dataset should be divided into independently recoverable scopes, then select scope size from record complexity and downstream effects—not the default alone. Define idempotency, partial-success handling, reconciliation and retry rules before moving the boundary. More heap in an asynchronous context is a property of the tool, not a substitute for deciding what must succeed together.
Keep serialisation boundaries small
Asynchronous work often carries state across a queue boundary. Passing a rich graph of sObjects and wrappers into a Queueable job can make the submission itself expensive, preserve stale data and obscure which fields the job truly owns. Re-reading by stable identifiers inside the job usually produces a clearer contract and lets the execution apply current sharing, state and validation rules deliberately.
Pass identifiers, operation keys and compact immutable parameters where possible. Store large durable payloads in an appropriate record or file and let the job retrieve a bounded portion. Avoid Database.Stateful in Batch Apex unless cross-scope state is genuinely required; retaining state increases coupling between transactions and can reduce throughput. A serialised object graph is still architecture—even when the platform creates it for you.
Test the curve, not one successful volume
Heap failures are often nonlinear because one more parent adds hundreds of children, one response includes a large attachment or one map retains both old and new versions. Build tests around the worst plausible data shape: maximum record counts per parent, long text, large error responses, duplicate keys, null-heavy payloads and multiple automation paths sharing the same transaction. Record Limits.getHeapSize() at meaningful phase boundaries during diagnostic tests, not on every production iteration.
Set an internal operating margin well below the governor limit and alert on jobs that approach it. Track payload size, records per chunk, peak heap, CPU and failure distribution together because reducing heap can increase CPU or DML pressure. Re-run the profile when selectors, integrations or batch scope change. Winter ’27 gives Apex substantially more room; the right engineering response is to make resilient workloads safer, not to make unbounded workloads larger.
Official references
- Salesforce Help — Handle Larger Datasets with Increased Apex Heap Limits
- Salesforce Developers — The Salesforce Developer’s Guide to the Winter ’27 Release
- Salesforce Developers — Execution Governors and Limits
- Salesforce Developers — SOQL For Loops
- Salesforce Developers — Working with Very Large SOQL Queries
- Salesforce Developers — Use Batch Apex
- Salesforce Developers — JSONParser Class
- Salesforce Architects — Scalability Patterns