The Apex heap size limit is a governor limit that restricts the amount of memory an Apex transaction can use at one time. When this limit is exceeded, the transaction is immediately terminated and all DML operations are rolled back — resulting in failed automations, incomplete data operations, and errors visible to end users. With the Signature Success plan’s Proactive Monitoring, Salesforce proactively monitors Apex Heap Limit Exceeded error rates in your organization and alerts you when error counts reach elevated levels, enabling you to identify and resolve problematic code before it impacts business operations at scale. In addition, on the Salesforce Help site Designated contacts and above can see your realtime metrics, alerts & more.
SOQL queries returning too many records — Queries that fetch large result sets into collections consume heap memory rapidly, especially within loops.
Large string concatenations in loops — Building strings iteratively without using efficient alternatives causes unbounded memory growth.
Unbounded list or map growth — Collections that grow without pagination or size limits can exhaust heap memory in bulk operations.
Deserializing large JSON or XML payloads — Parsing large external payloads into Apex objects places significant memory pressure on the transaction.
Inefficient triggers processing bulk operations — Triggers that do not follow bulk-safe patterns can exceed heap limits when processing large record sets.
Avoid placing SOQL queries inside loops and use selective filters to limit the number of records returned into collections. Use the Query Plan Tool to identify and optimize inefficient queries. For large data sets, implement pagination using SOQL LIMIT/OFFSET or Database.QueryLocator to process records in smaller chunks. Review the SOQL and SOSL Reference for query optimization guidance.
Refactor code to avoid large string concatenations in loops and unbounded collection growth. Use Limits.getHeapSize() and Limits.getLimitHeapSize() in debug logs to identify where memory consumption is growing within a transaction. Review the Apex Best Practices and Execution Governors and Limits documentation for guidance on writing memory-efficient Apex.
When deserializing large JSON or XML payloads, consider processing data in smaller segments rather than parsing entire payloads in a single transaction. Where possible, move large payload processing to asynchronous contexts such as Batch Apex or Queueable Apex, which provide independent governor limit contexts per execution.
005388769

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.