Salesforce Certified Platform Developer II — Question 128
A developer encounters an error that states that the Apex heap size is exceeded.
Which technique may reduce heap size?
Answer options
- A. Add the transient keyword to the variable definition
- B. Move the variable definition inside the scope of the function
- C. Use static variables instead of instance variables
- D. Use SOQL for loops instead of standard SOQL queries
Correct answer: D
Explanation
Using SOQL for loops allows you to process records in smaller chunks, which can significantly reduce the heap size by limiting the amount of data held in memory at one time. The other options, while they may have their own benefits, do not directly address the issue of heap size in the same effective manner as using SOQL for loops.