Plat-Dev-301 practice question 2 of 10

The Account object has a field, Audit_Code__c, that is used to specify what type of auditing theAccount needs and a Lookup to User, Auditor__c, that…

Choose your answer, then check it against the explanation.

The Account object has a field, Audit_Code__c, that is used to specify what type of auditing the

Account needs and a Lookup to User, Auditor__c, that is the assigned auditor. When an Account is

initially created, the user specifies the Audit_Code__c. Each User in the org has a unique text field,

Audit_Code__c, that is used to automatically assign the correct user to the Account's Auditor__c

field.

Trigger:

Java

trigger AccountTrigger on Account (before insert) {

AuditAssigner.setAuditor(Trigger.new);

}

Apex Class:

Java

public class AuditAssigner {

public static void setAuditor(List<Account> accounts) {

for (User u : [SELECT Id, Audit_Code__c FROM User]) {

for (Account a : accounts) {

if (u.Audit_Code__c == a.Audit_Code__c) {

a.Auditor__c = u.Id;

}

}

}

}

}

What should be changed to most optimize the code's efficiency?

Answer options
Question 2 of 10

Keep practicing

Take the free Plat-Dev-301 practice test

Ten exam-style questions with answers and explanations, plus the exam facts and study guides.

Start the free practice test

More questions

Other Plat-Dev-301 practice questions

Scroll to Top