위치:
개체 상태 작업 정의에 대한 Apex 클래스 만들기
Developer Console에서 각 개체 상태 작업 정의(사용자 정의 작업)에 대해 호출 가능한 Apex 클래스를 만듭니다.
-
빠른 액세스 메뉴(
)를 클릭한 다음, 개발자 콘솔을 클릭합니다.
- 를 선택합니다.
- 이름을 입력하고 확인을 클릭합니다.
-
대화 상자에 샘플 코드를 붙여 넣습니다.
개체 상태 작업 정의의 샘플 Apex 호출 클래스를 참조하십시오.
- 변경 사항을 저장합니다.
See Also
개체 상태 작업 정의에 대한 샘플 Apex 호출 클래스
다음은 개체 상태 작업 정의를 생성하기 위한 몇 가지 Apex 클래스 샘플입니다. 요구 사항에 맞게 샘플 코드 수정
메서드 서명에는 다음 필수 매개 변수가 포함됩니다.
| 매개 변수 | 상세 설명 |
|---|---|
| Map < String, Object > inputMap | 두 개의 키를 포함합니다.
|
| 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);
}
}
}
샘플 승인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');
}
}
