C & D
A)Use the "transient" keyword when declaring variables
Yes you were spot on with transient. Declaring a variable as transient wont' make it part of view state. Also declaring a transient variable will make sure its not serialized(JSON.deserialize). But it will still be part of heap. Transient variable has nothing to do with heap, Thus it won't be a correct option.
B)Query and store fields from a related object in a collection when updating related objects
This feels illogical and overhead to store fields of related object in a collection, and is wrong in my opinion.
C) Remove or set a collection to null after use
There is garbage collection and heap deallocation. It happens when the block where you have declared the variable ends. If you wanna free up heap before the end of block and you don't have any use of that variable later then it makes sense to make it null and free up some heap. It's correct and good practice to do so if playing with a huge chunk of records
D) Best practice to avoid SOQL for loops
The link also mentions removing items from collection, point 4:
1. Look for heap size in debug logs. If heap size is approaching the limit, investigate it and refactor the code.
2. Use the 'Transient' keyword with variables. It is used to declare instance variables that cannot be saved, and shouldn’t be transmitted as part of the view state for a Visualforce page.
3. Use Limit methods. Use heap limits methods in your Apex code to monitor/manage the heap during execution.
4. Reduce heap size during runtime by removing items from the collection as you iterate over it.
5. Use SOQL for loops. To avoid heap size limits, developers should always use a SOQL "for" loop to process query results that return many records.
The question is asking for a trigger. It is C & D. Clear the set list after use, the documentation also gives a way to do this and us the SOQL for loops.
Why "A" is not the answer - Declaring a variable as transient wont' make it part of view state. Also declaring a transient variable will make sure its not serialized(JSON.deserialize). But it will still be part of heap. Transient variable has nothing to do with heap, Thus it won't be a correct option.
from the doc :
Use the transient keyword to declare instance variables that can't be saved, and shouldn't be transmitted as part of the view state for a Visualforce page.
transient is solution for visualforce 'heap' limit that is view state.
the question is pertaining to Trigger.
so i think the correct answer is C & D
from the doc :
Use the transient keyword to declare instance variables that can't be saved, and shouldn't be transmitted as part of the view state for a Visualforce page.
transient is solution for visualforce 'heap' limit that is view state.
the question is pertaining to Trigger.
so i think the correct answer is D & D
upvoted 2 times
...
Log in to ExamTopics
Sign in:
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
ugaponova
Highly Voted 4 years, 3 months agoAK2020
Highly Voted 4 years, 4 months agoHR444
3 years, 2 months agozanstaszek9
2 years, 9 months agoPrivateUser
Most Recent 1 month agoThanh201
1 month, 2 weeks agoPriyankN
8 months, 1 week agoEtwang
9 months agochucksback
1 year agoronak_h33t
1 year, 11 months agoDean5555
2 years, 1 month agoishanjn05
2 years, 3 months agozenchouu
2 years, 4 months agozenchouu
2 years, 4 months ago