詳細情報:
オブジェクト状態のアクション定義の Apex クラスの作成
開発者コンソールで、オブジェクト状態のアクション定義 (カスタムアクション) ごとに呼び出し可能な Apex クラスを作成します。
-
クイックアクセスメニュー (
) をクリックし、[開発者コンソール] をクリックします。
- [)]、[Apex クラス)] の順に選択します。
- 名前を入力し、[OK] をクリックします。
-
サンプルコードをダイアログボックスに貼り付けます。
「オブジェクト状態アクション定義の Apex 呼び出しクラスのサンプル」を参照してください。
- 変更内容を保存します。
See Also
オブジェクト状態アクション定義の Apex 呼び出しクラスのサンプル
オブジェクト状態のアクション定義を作成するための Apex クラスのサンプルを次に示します。要件に合わせてサンプルコードを変更する
メソッド署名には、次の必須パラメーターが含まれます。
| パラメーター | 説明 |
|---|---|
| Map < String, Object > inputMap | 次の 2 つのキーが含まれます。
|
| Map < String, Object > outMap |
|
RestartContract Apex クラスのサンプル
カスタムアクションを使用して、終了した契約を再開します。
global class RestartContract implements industries_clm.OpenInterface {
public Boolean invokeMethod(String methodName, Map<String, Object> request, Map<String, Object> outMap) {
Boolean success = true;
if (methodName == 'executeAction') {
makeCallout(request, outMap);
}
return success;
}
public static void makeCallout(Map < String, Object > inputMap, Map < String, Object > outMap) {
String ContractId = (String) inputMap.get('contractId');
List<Contract> contract = [SELECT Id, Name, Status FROM Contract WHERE Id =:contractId];
contract[0].Status = 'Draft';
update(contract);
outMap.put('isSuccess', true);
}
}
}
ApprovalAction Apex クラスのサンプル
標準の Salesforce 承認プロセスと同時に実行される追加ロジックを実装します。
global class ApprovalAction implements industries_clm.OpenInterface {
public Boolean invokeMethod(String methodName, Map<String, Object> request, Map<String, Object> outMap) {
Boolean success = true;
if (methodName == 'executeAction') {
executeAction(request, outMap);
}
return success;
}
private void executeAction(Map < String, Object > inputMap, Map < String, Object > outMap) {
Approval.ProcessSubmitRequest req1 =
new Approval.ProcessSubmitRequest();
req1.setComments('Submitting request for approval.');
String contractId = (String) inputMap.get('contractId');
req1.setObjectId(contractId);
// Submit the record to specific process and skip the criteria evaluation
req1.setProcessDefinitionNameOrId('ContractApprovalProcessName');
req1.setSkipEntryCriteria(true);
// Submit the approval request for the account
Approval.ProcessResult result = Approval.process(req1);
outMap.put('isSuccess', true);
}
}
EndContract Apex クラスのサンプル
コールされたアクションでは、複数の To 状態が使用可能なため、From 状態に対して複数のオブジェクト状態遷移が可能な場合、Apex は契約の状態を変更しません。たとえば、有効化された契約で、契約を 2 つの状態 (キャンセル済みと解除済み) に移行するように設定された [終了契約] というカスタムアクションがあるとします。Apex コールを正常に実行するには、 finalStatusValue パラメータが必要です。
global class EndContract implements industries_clm.OpenInterface {
public Boolean invokeMethod(String methodName, Map<String, Object> request, Map<String, Object> outMap) {
Boolean success = true;
if (methodName == 'executeAction') {
executeAction(request, outMap);
}
return success;
}
private void executeAction(Map < String, Object > inputMap, Map < String, Object > outMap) {
String contractId = (String) inputMap.get('contractId');
outMap.put('isSuccess', true);
outMap.put('finalStatusValue', 'Canceled');
}
}
