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;
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;
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;
List accountUpdates = new List(); for ( Account a : [SELECT Id, Type FROM Account]){ a.Status = a.Type == 'Customer' ? 'Active' : 'Pending'; accountUpdates.add(a); } update accountUpdates;