Showing results for 
Search instead for 
Did you mean: 

Why am I getting error message system.limitexception: apex heap size too large: 9466166 External Entry Point

Fry Chef
Fry Chef

Why am I getting error message system.limitexception: apex heap size too large: 9466166 External Entry Point

Why am I getting error message system.limitexception: apex heap size too large: 9466166 External Entry Point

Staff Chef
Staff Chef

Re: Why am I getting error message system.limitexception: apex heap size too large: 9466166 External Entry Point

Hi Lisa Streator​, what you are hitting is a Salesforce Limit. I will post some information on this and ways to try to avoid it. However based on your given job title (in the community) I am assuming you aren't the person writing the code for your organisation? If so then it may be best to log a ticket with your internal support or ask ServiceMax Support for help by logging a ticket with them.

Information on how to avoid hitting the heap size limit:

Source for the below: Salesforce Developers

Per-Transaction Apex Limits

These limits count for each Apex transaction. For Batch Apex, these limits are reset for each execution of a batch of records in the execute method.

This table lists limits for synchronous Apex and asynchronous Apex (Batch Apex and future methods) when they’re different. Otherwise, this table lists only one limit that applies to both synchronous and asynchronous Apex.

DescriptionSynchronous LimitAsynchronous Limit
Total number of SOQL queries issued1 (This limit doesn’t apply to custom metadata types. In a single Apex transaction, custom metadata records can have unlimited SOQL queries.)100200
Total number of records retrieved by SOQL queries50,000
Total number of records retrieved by Database.getQueryLocator10,000
Total number of SOSL queries issued20
Total number of records retrieved by a single SOSL query2,000
Total number of DML statements issued2150
Total number of records processed as a result of DML statements, Approval.process, or database.emptyRecycleBin10,000
Total stack depth for any Apex invocation that recursively fires triggers due to insert,update, or delete statements316
Total number of callouts (HTTP requests or Web services calls) in a transaction100
Maximum cumulative timeout for all callouts (HTTP requests or Web services calls) in a transaction120 seconds
Maximum number of methods with the future annotation allowed per Apex invocation50
Maximum number of Apex jobs added to the queue with System.enqueueJob50
Total number of sendEmail methods allowed10
Total heap size46 MB12 MB
Maximum CPU time on the Salesforce servers510,000 milliseconds60,000 milliseconds
Maximum execution time for each Apex transaction10 minutes
Maximum number of push notification method calls allowed per Apex transaction10
Maximum number of push notifications that can be sent in each push notification method call2,000

1 In a SOQL query with parent-child relationship subqueries, each parent-child relationship counts as an extra query. These types of queries have a limit of three times the number for top-level queries. The row counts from these relationship queries contribute to the row counts of the overall code execution. In addition to static SOQL statements, calls to the following methods count against the number of SOQL statements issued in a request.

  • Database.countQuery
  • Database.getQueryLocator
  • Database.query

2 Calls to the following methods count against the number of DML queries issued in a request.

  • Approval.process
  • Database.convertLead
  • Database.emptyRecycleBin
  • Database.rollback
  • Database.setSavePoint
  • delete and Database.delete
  • insert and Database.insert
  • merge and Database.merge
  • undelete and Database.undelete
  • update and Database.update
  • upsert and Database.upsert
  • System.runAs

3 Recursive Apex that does not fire any triggers with insert, update, or delete statements exists in a single invocation, with a single stack. Conversely, recursive Apex that fires a trigger spawns the trigger in a new Apex invocation, separate from the invocation of the code that caused it to fire. Because spawning a new invocation of Apex is a more expensive operation than a recursive call in a single invocation, there are tighter restrictions on the stack depth of these types of recursive calls.4 Email services heap size is 36 MB.5 CPU time is calculated for all executions on the Salesforce application servers occurring in one Apex transaction. CPU time is calculated for the executing Apex code, and for any processes that are called from this code, such as package code and workflows. CPU time is private for a transaction and is isolated from other transactions. Operations that don’t consume application server CPU time aren’t counted toward CPU time. For example, the portion of execution time spent in the database for DML, SOQL, and SOSL isn’t counted, nor is waiting time for Apex callouts.

  • Limits apply individually to each testMethod.
  • To determine the code execution limits for your code while it is running, use the Limits methods. For example, you can use the getDMLStatements method to determine the number of DML statements that have already been called by your program. Or, you can use the getLimitDMLStatements method to determine the total number of DML statements available to your code.

Regards, Richard

~If my post was useful, please give me a thumbs up! Mark correct answers as 'solutions' so we can all find answers faster!~