Exam PDII Topic 11 Question 147 Discussion
Actual exam question for Salesforce's PDII exam
Question #: 147
Topic #: 11
Question #: 147
Topic #: 11
Refer to exhibit.

Consider the above trigger intended to assign the Account to the manager of the Account's region, Which two changes should a developer make in this trigger to adhere to best practices?

Consider the above trigger intended to assign the Account to the manager of the Account's region, Which two changes should a developer make in this trigger to adhere to best practices?
Suggested Answer: B,D Vote an answer
The two changes that the developer should make in this trigger to adhere to best practices are to move the Region__c query to outside the loop and to remove the last line updating accountList as it is not needed. Moving the Region__c query to outside the loop avoids the SOQL query limit, as it reduces the number of queries from one per Account record to one for all Account records. The developer can use a Map to store the Region__c records by Name, and then use the Map to assign the OwnerId for each Account record. Removing the last line updating accountList as it is not needed avoids the DML statement limit, as it is redundant to update the records that are already in the trigger context. The developer can use the Trigger.new list to modify the Account records, and the changes will be saved automatically after the trigger execution. Using a Map to cache the results of the Region__c query by Id is not a valid answer, as it does not move the query outside the loop, and it does not match the Name field of the Account record. Using a Map accountMap instead of List accountList is not a valid answer, as it does not affect the query or the DML limits, and it does not change the logic of the trigger. Reference: [Apex Triggers], [Apex Best Practices], [Apex Developer Guide]
by Ed at Oct 02, 2024, 09:16 AM
0
0
0
10
Comments
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.
Report Comment
Commenting
You can sign-up / login (it's free).