Tag Archives: Recall

Recall Approval Process Using Apex In Salesforce

Sample Code:

//Object record id to recall the approval process
String recordId = '0065800000lQxxsAAC';
//Get Process Instance Work Items
ProcessInstanceWorkitem[] piWorkItems = [SELECT Id FROM ProcessInstanceWorkItem WHERE ProcessInstance.TargetObjectId = :recordId
                                         AND ProcessInstance.Status = 'Pending']; 
if(piWorkItems.size() > 0){
    //Create Process Work Item Request
    Approval.ProcessWorkItemRequest pwiRequest = new Approval.ProcessWorkItemRequest();
    pwiRequest.setAction('Removed');
    pwiRequest.setWorkItemId(piWorkItems[0].Id);
    Approval.ProcessResult result = Approval.process(pwiRequest);
}