Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
This code is used in apex heap size error resolution tutorial of SFDC Stop
List<Account> accounts = new List<Account>();
for(Integer i=1; i<=10000; i++) {
accounts.add(new Account(Name = 'Account ' + i));
}
insert accounts;
List<Account> accounts = [SELECT Id FROM Account];
System.debug('Heap size when queried list of accounts = ' + Limits.getHeapSize());
for(List<Account> accounts : [SELECT Id FROM Account]) {
System.debug(Limits.getHeapSize());
}
System.debug('Max heap size after an SOQL for loop = ' + Limits.getHeapSize());
void callMe()
{
List<Account> accounts = [SELECT Id FROM Account];
System.debug(Limits.getHeapSize());
}
callme();
System.debug(Limits.getHeapSize());
List<Account> accounts = [SELECT Id FROM Account];
System.debug('Heap size when queried list of accounts = ' + Limits.getHeapSize());
accounts = null;
System.debug('Heap size when list is null = ' + Limits.getHeapSize());
List<Account> accounts = [SELECT Id FROM Account];
System.debug('Heap size when queried list of accounts = ' + Limits.getHeapSize());
accounts.clear();
System.debug('Heap size when list is cleared = ' + Limits.getHeapSize());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment