User Story
Create a program which updates all the Accounts Rating as Cold
.
Code
1st Way:
public class UpdateAccounts{
public static void UpdateAccountRating() {
Account[] acList = [SELECT Id, Rating FROM Account WHERE Rating != 'Cold'];
for (Account ac: acList ) {
ac.Rating= 'Cold';
}
update acList;
}
}
2nd Way
public class UpdateAccounts{
public static void UpdateAccountRating() {
Account[] acList = [SELECT Id, Rating FROM Account];
for (Account ac: acList ) {
if(ac.Rating != 'Cold'){
ac.put('Rating','Cold');
}
}
update acList;
}
}
Execute the Program:
UpdateAccounts.UpdateAccountRating();
Video
Video does not exists.