Add a method to a Apex Class, Execute the method to update the Accounts queried (Know how to write and execute method in a class. Also, you will get the answer for error like 'System.DmlException: Update failed.....theField__c field is mandatory:[theField__c]')
Apex Class:
public class GoldAccountsUtility {
public static void updateGoldAccounts() {
// Get the 2 oldest accounts
Account[] oldAccounts = [SELECT Id, Description,Region__c FROM Account ORDER BY CreatedDate ASC LIMIT 2];
// loop through them and update the Description field
for (Account acct : oldAccounts) {
acct.Region__c = 'APAC';
acct.Description = 'Gold Account';
}
// update Accounts
update oldAccounts;
}
}
Execute from Anonymous Window:
GoldAccountsUtility.updateGoldAccounts();
Comments
Post a Comment