Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@sfdcfanboy
Created July 20, 2017 09:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sfdcfanboy/6976c9cf0bbd579ad35c283a6767f6e6 to your computer and use it in GitHub Desktop.
Save sfdcfanboy/6976c9cf0bbd579ad35c283a6767f6e6 to your computer and use it in GitHub Desktop.
public class ApprovalProcessor {
webservice void submitAndProcessApprovalRequest() {
// Create an approval request for the account
Approval.ProcessSubmitRequest req1 = new Approval.ProcessSubmitRequest();
req1.setComments('Submitting 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('PTO_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(
'Pending', result.getInstanceStatus(),
'Instance Status'+result.getInstanceStatus());
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment