PrepAway - Latest Free Exam Questions & Answers

Which code block will accurately meet the business requirements?

A developer is asked to update data in an org based on new business rules. The new rules state that Accounts with the type set to ‘Customer’ should have a status of ‘Active’, and Accounts with the type set to ‘Prospect’ should have a status of ‘Pending’. No other changes to data should be made.

Which code block will accurately meet the business requirements?

A. Map statusMap = new Map{‘Customer’=>’Active’, ‘Prospect’=>’Pending’}
List accountUpdates = new List();
for ( Account a : [SELECT Id, Type FROM Account]){
if ( statusMap.containsKey(a.Type) ) {
a.Status = a.Type == ‘Customer’ ? ‘Active’ : ‘Pending’;
}
accountUpdates.add(a);
}
update accountUpdates;

B. Map statusMap = new Map{‘Customer’=>’Active’, ‘Prospect’=>’Pending’}
List accountUpdates = new List();
for ( Account a : [SELECT Id, Type FROM Account WHERE Status IN :statusMap.keySet()]){
a.Status = statusMap.get(a.Type);
accountUpdates.add(a);
}
update accountUpdates;

C. List accountUpdates = new List();
for ( Account a : [SELECT Id, Type FROM Account]){
if ( String.isNotBlank(a.Type) && a.Type == ‘Customer’ ){
a.Status = ‘Active’;
}
if ( String.isNotBlank(a.Type) && a.Type == ‘Prospect’ ){
a.Status = ‘Pending’;
}
accountUpdates.add(a);
}
update accountUpdades;

D. List accountUpdates = new List();
for ( Account a : [SELECT Id, Type FROM Account]){
a.Status = a.Type == ‘Customer’ ? ‘Active’ : ‘Pending’;
accountUpdates.add(a);
}
update accountUpdates;


Leave a Reply