Salesforce Certified Platform Developer II — Question 3

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.)

Answer options

Correct answer: B, C

Explanation

Moving the Region__c query outside the loop (option B) prevents multiple queries from being executed, which can lead to governor limit issues. Removing the update statement (option C) is also necessary because the trigger operates on the records already being modified, making the update redundant. The other options, while they may improve efficiency, do not address the immediate best practice concerns in this scenario.