Salesforce
PDII · Question #412
PDII Question #412: Real Exam Question with Answer & Explanation
Sign in or unlock PDII to reveal the answer and full explanation for question #412. The question stem and answer options stay visible for context.
Question
trigger AssignOwnerByRegion on Account ( before insert, before update ) { List<Account> accountList = new List<Account>(); for( Account anAccount : trigger.new ) { Region__c theRegion = [ SELECT Id, Name, Region_Manager__c FROM Region__c - WHERE Name = :anAccount.Region_Name__c ]; anAccount.OwnerId = theRegion.Region_Manager__c; accountList.add( anAccount ); } update accountList; } 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? (Choose two.)
Options
- AUse a Map to cache the results of the Region__c query by Id.
- BMove the Region__c query to outside the loop.
- CRemove the last line updating accountList as it is not needed.
- DUse a Map accountMap instead of List accountList.
Unlock PDII to see the answer
You've previewed enough free PDII questions. Unlock PDII for full answers, explanations, the timed quiz mode, progress tracking, and the master PDF. Question stem and options stay visible so you can still see what's on the exam.