鎵瑰噯杩囩▼鏄竴涓鏉傜殑涓氬姟杩囩▼銆傝缁嗙殑鍐呭鍙互鍙傝€冨畼鏂规枃妗c€?/p>
鍦ˋpex涓皟鐢ˋpproval Process
鍦ˋpex涓彲浠ヤ娇鐢ㄤ互涓嬬被瀵笰pproval Process杩涜鎿嶄綔锛?/p>
- ProcessInstance锛氬彲浠ョ敤鏉ユ煡璇㈡垨閬嶅巻Approval Process杩囩▼銆?/li>
- ProcessInstanceHistory锛氬彧璇诲璞★紝涓嶈兘鐩存帴琚玈OQL鏌ヨ銆備唬琛ㄤ簡Approval Process杩囩▼鐨勬墍鏈夋楠ゅ拰鐩稿叧鐨勭姸鎬佷负鈥減ending鈥濈殑璇锋眰銆?/li>
- ProcessInstanceStep锛氫唬琛ㄤ簡Approval Process杩囩▼鐨勪竴涓楠ゃ€?/li>
- ProcessInstanceWorkitem锛氫唬琛ㄤ簡Approval Process杩囩▼鐩稿叧鐨勭姸鎬佷负鈥減ending鈥濈殑璇锋眰銆?/li>
鍦ˋpex涓彲浠ヤ娇鐢⊿OQL瀵筆rocessInstance杩涜鏌ヨ锛岃€屽浜庡叾浠栦笁涓被鐨勬煡璇竴鑸槸浣滀负瀵筆rocessInstance鏌ヨ鐨勫瓙璇彞鏉ヨ繘琛屻€?/p>
SELECT Id, (SELECT Id, StepStatus, Comments FROM Steps)
FROM ProcessInstance
涓婇潰杩欐浠g爜鍙互鏌ヨApproval Process杩囩▼鐨処d锛屽苟鏌ヨ鍏跺寘鎷殑姝ラ鐨勫悇涓睘鎬с€?/p>
SELECT Id, (SELECT Id, ActorId, ProcessInstanceId FROM Workitems)
FROM ProcessInstance
涓婇潰杩欐浠g爜鍙互鏌ヨApproval Process鐩稿叧鐨勭姸鎬佷负鈥減ending鈥濈殑璇锋眰锛圵orkitems锛夈€?/p>
SELECT Id, (SELECT Id, StepStatus, Comments FROM StepsAndWorkitems)
FROM ProcessInstance
涓婇潰杩欐浠g爜鍙互鏌ヨApproval Process杩囩▼鐨勫巻鍙茶褰曘€?/p>
SELECT Id, ActorId, ProcessInstanceId
FROM ProcessInstanceWorkitem
WHERE ProcessInstanceId = 鈥榅XXX鈥?
涓婇潰杩欐浠g爜鍙互鏌ヨ鍜屾煇涓狝pproval Process鐨勭浉鍏崇殑鎵€鏈夌姸鎬佷负鈥減ending鈥濈殑璇锋眰銆?/p>
瀹樻柟浠g爜绀轰緥
浠ヤ笅浠g爜鎷疯礉鑷?a href="https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_process_example.htm">瀹樻柟鏂囨。锛屼綔涓轰娇鐢ˋpproval Process鐨勭ず渚嬶細
public class TestApproval {
void submitAndProcessApprovalRequest() {
// Insert an account
Account a = new Account(Name=鈥楾est鈥?annualRevenue=100.0);
insert a;
User user1 = [SELECT Id FROM User WHERE Alias=鈥楽omeStandardUser鈥榏;
// Create an approval request for the account
Approval.ProcessSubmitRequest req1 =
new Approval.ProcessSubmitRequest();
req1.setComments(鈥楽ubmitting request for approval.鈥?;
req1.setObjectId(a.id);
// Submit on behalf of a specific submitter
req1.setSubmitterId(user1.Id);
// Submit the record to specific process and skip the criteria evaluation
req1.setProcessDefinitionNameOrId(鈥楶TO_Request_Process鈥?;
req1.setSkipEntryCriteria(true);
// Submit the approval request for the account
Approval.ProcessResult result = Approval.process(req1);
// Verify the result
System.assert(result.isSuccess());
System.assertEquals(
鈥楶ending鈥? result.getInstanceStatus(),
鈥業nstance Status鈥?result.getInstanceStatus());
// Approve the submitted request
// First, get the ID of the newly created item
List<Id> newWorkItemIds = result.getNewWorkitemIds();
// Instantiate the new ProcessWorkitemRequest object and populate it
Approval.ProcessWorkitemRequest req2 =
new Approval.ProcessWorkitemRequest();
req2.setComments(鈥楢pproving request.鈥?;
req2.setAction(鈥楢pprove鈥?;
req2.setNextApproverIds(new Id[] {UserInfo.getUserId()});
// Use the ID from the newly created item to specify the item to be worked
req2.setWorkitemId(newWorkItemIds.get(0));
// Submit the request for approval
Approval.ProcessResult result2 = Approval.process(req2);
// Verify the results
System.assert(result2.isSuccess(), 鈥楻esult Status:鈥?result2.isSuccess());
System.assertEquals(
鈥楢pproved鈥? result2.getInstanceStatus(),
鈥業nstance Status鈥?result2.getInstanceStatus());
}
}