Created
October 2, 2021 07:48
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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