Newer Version Available
UnlockResult Class
Namespace
Usage
Example
The following example shows how to obtain and iterate through the returned Approval.UnlockResult objects. It locks some queried accounts using Approval.unlock with a false second parameter to allow partial processing of records on failure. Next, it iterates through the results to determine whether the operation was successful for each record. It writes the ID of every record that was processed successfully to the debug log, or writes error messages and failed fields of the failed records.
1// Query the accounts to unlock
2Account[] accts = [SELECT Id from Account WHERE Name LIKE 'Acme%'];
3
4for(Account acct:accts) {
5 // Create an approval request for the account
6 Approval.ProcessSubmitRequest req1 =
7 new Approval.ProcessSubmitRequest();
8 req1.setComments('Submitting request for approval.');
9 req1.setObjectId(acct.id);
10
11 // Submit the record to specific process and skip the criteria evaluation
12 req1.setProcessDefinitionNameOrId('PTO_Request_Process');
13 req1.setSkipEntryCriteria(true);
14
15 // Submit the approval request for the account
16 Approval.ProcessResult result = Approval.process(req1);
17
18 // Verify the result
19 System.assert(result.isSuccess());
20}
21
22// Unlock the accounts
23Approval.UnlockResult[] urList = Approval.unlock(accts, false);
24
25// Iterate through each returned result
26for(Approval.UnlockResult ur : urList) {
27 if (ur.isSuccess()) {
28 // Operation was successful, so get the ID of the record that was processed
29 System.debug('Successfully unlocked account with ID: ' + ur.getId());
30 }
31 else {
32 // Operation failed, so get all errors
33 for(Database.Error err : ur.getErrors()) {
34 System.debug('The following error has occurred.');
35 System.debug(err.getStatusCode() + ': ' + err.getMessage());
36 System.debug('Account fields that affected this error: ' + err.getFields());
37 }
38 }
39}UnlockResult Methods
The following are methods for UnlockResult.
getErrors()
Signature
public List<Database.Error> getErrors()
Return Value
Type: List<Database.Error>
getId()
Signature
public Id getId()
Return Value
Type: Id
Usage
If the field contains a value, the object was unlocked. If the field is empty, the operation was not successfult.
isSuccess()
Signature
public Boolean isSuccess()
Return Value
Type: Boolean