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: http://blog.jeffdouglas.com/2010/08/16/managing-the-heap-in-salesforce-com/
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.
|Description||Synchronous Limit||Asynchronous 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.)||100||200|
|Total number of records retrieved by SOQL queries||50,000|
|Total number of records retrieved by Database.getQueryLocator||10,000|
|Total number of SOSL queries issued||20|
|Total number of records retrieved by a single SOSL query||2,000|
|Total number of DML statements issued2||150|
|Total number of records processed as a result of DML statements, Approval.process, or database.emptyRecycleBin||10,000|
|Total stack depth for any Apex invocation that recursively fires triggers due to insert,update, or delete statements3||16|
|Total number of callouts (HTTP requests or Web services calls) in a transaction||100|
|Maximum cumulative timeout for all callouts (HTTP requests or Web services calls) in a transaction||120 seconds|
|Maximum number of methods with the future annotation allowed per Apex invocation||50|
|Maximum number of Apex jobs added to the queue with System.enqueueJob||50|
|Total number of sendEmail methods allowed||10|
|Total heap size4||6 MB||12 MB|
|Maximum CPU time on the Salesforce servers5||10,000 milliseconds||60,000 milliseconds|
|Maximum execution time for each Apex transaction||10 minutes|
|Maximum number of push notification method calls allowed per Apex transaction||10|
|Maximum number of push notifications that can be sent in each push notification method call||2,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.
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.