Salesforce Platform Developer I (legacy) — Question 18
A developer encounters APEX heap limit errors in a trigger.
Which two methods should the developer use to avoid this error? (Choose two.)
Answer options
- A. Use the transient keyword when declaring variables.
- B. Query and store fields from the related object in a collection when updating related objects.
- C. Remove or set collections to null after use.
- D. Use SOQL for loops instead of assigning large queries results to a single collection and looping through the collection.
Correct answer: C, D
Explanation
The correct answers, C and D, help manage memory usage effectively. Option C prevents memory bloat by ensuring collections are cleared after their purpose is served, while option D optimizes memory by processing records in smaller chunks rather than loading everything into one large collection. Options A and B do not directly address heap limit issues.