Skip to content

Instantly share code, notes, and snippets.

@rahulmalhotra
Created October 2, 2021 07:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rahulmalhotra/460dbed6a26090d0bc70940cecd20208 to your computer and use it in GitHub Desktop.
Save rahulmalhotra/460dbed6a26090d0bc70940cecd20208 to your computer and use it in GitHub Desktop.
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