Loading

Proactive Alert Monitoring: Apex Heap Limit Exceeded Errors

Fecha de publicación: Aug 7, 2026
Descripción

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.

 

Solución

Causes

  • 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.


Resolution

Inefficient SOQL Queries

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.

Inefficient Apex Code

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.

Large Payload Processing

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.

 

Recursos adicionales

Additional Resources

Help and Developer Resources

Useful Trails

Número del artículo de conocimiento

005388769

 
Cargando
Salesforce Help | Article