UnlockResult クラス
名前空間
使用方法
System.Approval.unlock() メソッドは Approval.UnlockResult オブジェクトを返します。UnlockResult 配列の各要素は、unlock メソッドへのパラメータとして渡された ID または sObject 配列の要素に対応します。UnlockResult 配列の最初の要素は ID または sObject 配列の最初の要素に対応し、2 つ目の要素は 2 つ目の要素、というように対応します。ID または sObject が 1 つのみ渡された場合、UnlockResult 配列には 1 つの要素が含まれます。
例
次の例は、返された Approval.UnlockResult オブジェクトを取得して反復処理する方法を示します。Approval.unlock の 2 番目のパラメータに false を指定して使用し、一部のクエリ済み取引先をロックして、失敗時にレコードの部分的な処理を行えるようにしています。次に、結果を反復処理して、レコードごとに操作が成功したかどうかを判別します。正常に処理された場合はそのレコードの ID、失敗した場合はそのレコードのエラーメッセージと失敗した項目をデバッグログに書き込みます。
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 のメソッド
UnlockResult のメソッドは次のとおりです。