April 7, 2018

Recall Approval Process using Apex in Salesforce

Sample Code:

ProcessInstanceWorkitem[] workItems = [ SELECT Id
                FROM ProcessInstanceWorkitem 
                WHERE ProcessInstance.TargetObjectId = '0016A00000OXbfi'
                AND ProcessInstance.Status = 'Pending' ]; 
Approval.ProcessWorkitemRequest pwr = new Approval.ProcessWorkitemRequest();  
pwr.setAction('Removed');
pwr.setWorkItemId(workItems[0].id);

Approval.ProcessResult result = Approval.process(pwr);

Output:


2 comments:

  1. Replies
    1. Check this https://www.infallibletechie.com/2020/03/sample-apex-class-public-class.html

      Delete