function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Apex Heap size is too large.



I have a test method for a Apex class.I'm getting more than 75 % coverage on test method. If i deploy the test method from sandbox to Production org then i'm getting the following Error.


'Apex Heap Size is too Large'.


Please suggest any solution for this.


Thanks in advance.




It usually means that you've created too many objects in your test method.  According to the docs, the heap size is limited to 1,000,000 bytes per test method.


Are you creating a large list of objects or similar?


use limits.getHeapSize() to keep an eye on the size of the heap. Using this you can take alternate approach if the heap size is close to governer limit of 1,000,000 bytes in a test method.


if (limits.getHeapSize > 90000) {

handle this with alternate logic;




I am also facing the same problem. I got the test coverage morethan 75%. But i got the error as 'Apex heap size too large: 4189528'  when we deploying. How to solve this. If you find any solution please help me. Thanks in advance.