Loading
弊社ヘルプサイトの Agentforce でケース作成フォームが表示されない場合の対応方法続きを読む
メールアドレスがデフォルトのログイン方式となります 続きを読む
オブジェクト状態のアクション定義の Apex クラスの作成

オブジェクト状態のアクション定義の Apex クラスの作成

開発者コンソールで、オブジェクト状態のアクション定義 (カスタムアクション) ごとに呼び出し可能な Apex クラスを作成します。

  1. クイックアクセスメニュー (設定歯車アイコン) をクリックし、[開発者コンソール] をクリックします。
  2. [File | New (新規)]、[Apex Class (Apex クラス)] の順に選択します。
  3. 名前を入力し、[OK] をクリックします。
  4. サンプルコードをダイアログボックスに貼り付けます。
    「オブジェクト状態アクション定義の Apex 呼び出しクラスのサンプル」を参照してください。
  5. 変更内容を保存します。

オブジェクト状態アクション定義の Apex 呼び出しクラスのサンプル

オブジェクト状態のアクション定義を作成するための Apex クラスのサンプルを次に示します。要件に合わせてサンプルコードを変更する

メソッド署名には、次の必須パラメーターが含まれます。

パラメーター 説明
Map < String, Object > inputMap

次の 2 つのキーが含まれます。

  • contractId: SObjectId

  • objectStateActionDefinition: コールされたアクションのレコード。

  • actionData: API または対応付け <String, String> 種別のデフォルトアクションからの追加の詳細が含まれるアクション固有のデータ。

Map < String, Object > outMap
  • outMap.put('isSuccess', true): isSuccess パラメータが返されなかった場合、または isSuccess パラメータが false として返された場合、Apex アクションは失敗します。

  • outMap.put('finalStatusValue', '<abc>'): 呼び出されたアクションで同じ「From」状態と別の「To」状態の複数のオブジェクト状態遷移が可能な場合、Apex クラスは契約の「To」状態を変更しません。finalStatusValue を定義する必要があります。

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');
    }
}
 
読み込み中
Salesforce Help | Article