Loading
시스템 관리자에 대한 피싱 방지 MFA 및 전 직원사용자 MFA 적용 안내 더 많이 읽기
개체 상태 작업 정의에 대한 Apex 클래스 만들기

개체 상태 작업 정의에 대한 Apex 클래스 만들기

Developer Console에서 각 개체 상태 작업 정의(사용자 정의 작업)에 대해 호출 가능한 Apex 클래스를 만듭니다.

  1. 빠른 액세스 메뉴(설정 기어 아이콘)를 클릭한 다음, 개발자 콘솔을 클릭합니다.
  2. 파일 | 신규 Apex 클래스 를 선택합니다.
  3. 이름을 입력하고 확인을 클릭합니다.
  4. 대화 상자에 샘플 코드를 붙여 넣습니다.
    개체 상태 작업 정의의 샘플 Apex 호출 클래스를 참조하십시오.
  5. 변경 사항을 저장합니다.

개체 상태 작업 정의에 대한 샘플 Apex 호출 클래스

다음은 개체 상태 작업 정의를 생성하기 위한 몇 가지 Apex 클래스 샘플입니다. 요구 사항에 맞게 샘플 코드 수정

메서드 서명에는 다음 필수 매개 변수가 포함됩니다.

매개 변수 상세 설명
Map < String, Object > inputMap

두 개의 키를 포함합니다.

  • contractId: SObjectId

  • objectStateActionDefinition: 호출된 작업에 대한 레코드입니다.

  • actionData의 경우: Map <String, String> 유형의 API 또는 기본 작업의 추가 세부 사항이 포함된 작업별 데이터입니다.

Map < String, Object > 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);
        }
    }
}

샘플 승인Action 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 상태를 사용할 수 있으므로 보낸 사람 상태에 대해 여러 개체 상태 전환이 가능한 경우 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