Hello Trailblazers, in this post we're going to talk about the resolution of a very common error as given below:
First error: Exceeded max size limit of 12000000 OR First error: Exceeded max size limit of 6000000
This error appears when you've exceeded the heap size limit in a single transaction. The heap size limit for a synchronous transaction is 6MB and for an asynchronous transaction is 12MB. Asynchronous transactions basically consists of batch classes, future methods and queueable apex.
How to resolve this error?
List<Account> accounts = [SELECT Id FROM Account]; // Stores 50,000 records at max - greater heap size
for(List<Account> accounts : [SELECT Id FROM Account]) {
}
// Stores 200 records at max - lesser heap size
void callMe()
{
List<Account> accounts = [SELECT Id FROM Account];
System.debug(Limits.getHeapSize()); // Coming as: 321085
}
callme();
System.debug(Limits.getHeapSize()); // Coming as: 1044





























