Heap size is a common, yet neglected problem whenever it comes to Salesforce Apex development. Heap size in actual is the count of memory used by the variables, object instances in an Apex class. In order to store these objects & variables, memory is allocated in Salesforce which is derived from allocated Heap. The Heap size truly depends on the type of transaction, Salesforce provides a heap size limit of 6MB for synchronous transaction and 12 MB for asynchronous transaction. Whenever, too much data is stored during processing an error occurs prompting â€œApex heap size too largeâ€. You must have encountered this error at least once if you are a developer.
Here are a few tips to ensure that the heap limit does not exceed the maximum size and your code runs smoothly