Created
April 20, 2017 14:28
-
-
Save sfdcfanboy/81d06096d4c460357b7c4b3cda30edbc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Query the accounts to lock | |
Account[] accts = [SELECT Id from Account WHERE Name LIKE 'Acme%']; | |
// Lock the accounts | |
Approval.LockResult[] lrList = Approval.lock(accts, false); | |
// Iterate through each returned result | |
for(Approval.LockResult lr : lrList) { | |
if (lr.isSuccess()) { | |
// Operation was successful, so get the ID of the record that was processed | |
System.debug('Successfully locked account with ID: ' + lr.getId()); | |
} | |
else { | |
// Operation failed, so get all errors | |
for(Database.Error err : lr.getErrors()) { | |
System.debug('The following error has occurred.'); | |
System.debug(err.getStatusCode() + ': ' + err.getMessage()); | |
System.debug('Account fields that affected this error: ' + err.getFields()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment