Loading
为对象状态操作定义创建 Apex 类

为对象状态操作定义创建 Apex 类

在开发人员控制台中为每个对象状态操作定义(自定义操作)创建可调用 Apex 类。

  1. 单击快速访问菜单 (设置齿轮图标),然后单击开发人员控制台。
  2. 选择文件 | 新建 Apex 类 。
  3. 输入名称并单击确定。
  4. 将示例代码粘贴到对话框中。
    见对象状态操作定义的示例 Apex 调用类。
  5. 保存更改。

对象状态操作定义的示例 Apex 调用类

以下是一些用于创建对象状态操作定义的 Apex 类示例。修改示例代码以满足您的要求

方法签名包含这些强制参数:

参数 描述
映射 < 字符串、对象 > inputMap

包含两个密钥:

  • contractId:SObjectId

  • objectStateActionDefinition:被调用操作的记录。

  • actionData:特定于操作的数据,包含来自 API 或映射 <String, String> 类型的默认操作的其他详细信息。

映射 < 字符串、对象 > outMap
  • outMap.put('isSuccess', true)如果未返回 isSuccess 参数,或 isSuccess 参数返回为 false,Apex 操作将失败。

  • outMap.put('finalStatusValue', '<abc>'):如果被调用操作可能有多个具有相同“发件人”状态和不同“收件人”状态的对象状态转换,Apex 类不会改变合同的“收件人”状态。您必须定义 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 类示例

对于调用的操作,如果“发件人”状态可能有多个对象状态转换,因为多个“收件人”状态可用,Apex 不会改变合同的状态。例如,在激活的合同上,有一个称为结束合同的自定义操作,被配置为将合同移动到两种状态:已取消和已终止。要使 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