Welcome to ExamTopics
ExamTopics Logo
- Expert Verified, Online, Free.
exam questions

Exam CRT-450 All Questions

View all questions & answers for the CRT-450 exam

Exam CRT-450 topic 1 question 12 discussion

Actual exam question from Salesforce's CRT-450
Question #: 12
Topic #: 1
[All CRT-450 Questions]

A developer encounters APEX heap limit errors in a trigger.
Which two methods should the developer use to avoid this error? (Choose two.)

  • 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.
Show Suggested Answer Hide Answer
Suggested Answer: CD 🗳️

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
ugaponova
Highly Voted 4 years, 3 months ago
A&D
upvoted 19 times
...
AK2020
Highly Voted 4 years, 4 months ago
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
upvoted 5 times
HR444
3 years, 2 months ago
But that Salesforce article linked by @ugaponova seems to say using Transient variables IS a good way to do this.... which of you is correct?
upvoted 2 times
zanstaszek9
2 years, 9 months ago
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.
upvoted 3 times
...
...
...
PrivateUser
Most Recent 1 month ago
Selected Answer: AD
A & D According to official information:
upvoted 1 times
...
Thanh201
1 month, 2 weeks ago
Selected Answer: CD
C & D In Correct: The transient keyword is only applicable in Visualforce controllers, not triggers.
upvoted 1 times
...
PriyankN
8 months, 1 week ago
A&D
upvoted 1 times
...
Etwang
9 months ago
Selected Answer: AD
AD
upvoted 1 times
...
chucksback
1 year ago
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.
upvoted 1 times
...
ronak_h33t
1 year, 11 months ago
Selected Answer: AD
A and D
upvoted 2 times
...
Dean5555
2 years, 1 month ago
Selected Answer: CD
C&D as explained below
upvoted 4 times
...
ishanjn05
2 years, 3 months ago
Selected Answer: CD
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.
upvoted 3 times
...
zenchouu
2 years, 4 months ago
Selected Answer: CD
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
upvoted 4 times
...
zenchouu
2 years, 4 months ago
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
...
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.

SaveCancel
Loading ...