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?
- Map<String, String> statusMap = new Map<String, String>{'Customer'=>'Active', 'Prospect'=>'Pending'}
List<Account> accountUpdates = new List<Account>();
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; - Map<String, String> statusMap = new Map<String, String>{'Customer'=>'Active', 'Prospect'=>'Pending'}
List<Account> accountUpdates = new List<Account>();
for ( Account a : [SELECT Id, Type FROM Account WHERE Status IN :statusMap.keySet()]){
a.Status = statusMap.get(a.Type);
accountUpdates.add(a);
}
update accountUpdates; - List<Account> accountUpdates = new List<Account>();
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; - List<Account> accountUpdates = new List<Account>();
for ( Account a : [SELECT Id, Type FROM Account]){
a.Status = a.Type == 'Customer' ? 'Active' : 'Pending';
accountUpdates.add(a);
}
update accountUpdates;
Reveal Solution Next Question