Skip to content

Instantly share code, notes, and snippets.

@sfdcfanboy
Created April 20, 2017 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sfdcfanboy/81d06096d4c460357b7c4b3cda30edbc to your computer and use it in GitHub Desktop.
Save sfdcfanboy/81d06096d4c460357b7c4b3cda30edbc to your computer and use it in GitHub Desktop.
// 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