Error: Apex Heap Size Too Large
Issue
While syncing data to a Salesforce destination, records are rejected with the following error:
CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY: Apex heap size too large
Environment
Activations destination: Salesforce
Resolution
To resolve this issue:
- In Salesforce, find the Apex triggers, flows, and other automations on the object that Activations syncs to.
- Identify logic that processes too many records or stores too much data in memory. The heap size limit is 6 MB for synchronous Apex and 12 MB for asynchronous Apex.
- Reduce memory usage where possible:
- Move resource-intensive logic out of loops.
- Reuse query results instead of loading the same data multiple times.
- Avoid storing unnecessary large collections.
- If the logic can't run in a single synchronous transaction, move it to asynchronous Apex by using the Salesforce System.scheduleBatch() method.
- If the error continues, contact our support team to request a smaller batch size. Sending fewer records at a time may reduce memory usage.
A trigger processing a batch of 200 records may exceed the heap size limit if it also queries many related records, stores the results in multiple lists or maps, or keeps large text fields or JSON payloads in memory.
Cause
This issue occurs when automation associated with the target object uses more memory than Salesforce allows in a single transaction.
Activations sends data in batches, so Salesforce automation on the target object must support bulk processing. Complex triggers, large queries, large in-memory collections, or multiple layers of automation increase the likelihood of exceeding the heap size limit.