function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rabbani sayyed 8Rabbani sayyed 8 

How to recall a approved record using custom button (onclick javascript) ? can anyone share me the code for this?

salesforce mesalesforce me
hi check this once...
 
Apex Class:

global class approvalRecall
{
    webservice static void recallApproval(Id recId)    
    {        
        List<ProcessInstanceWorkitem> piwi = [SELECT Id, ProcessInstanceId, ProcessInstance.TargetObjectId FROM ProcessInstanceWorkitem WHERE ProcessInstance.TargetObjectId =: recId];
        Approval.ProcessWorkitemRequest req = new Approval.ProcessWorkitemRequest();
        req.setAction('Removed');        
        req.setWorkitemId(piwi.get(0).Id);
   
        Approval.process(req,false);
    }
}

Custom Button Javascript:

{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/15.0/apex.js")} 
var r = confirm("Are you sure want to recall the approval process?"); 
if(r == true) 
{ 
sforce.apex.execute("approvalRecall","recallApproval",{ID:"{!Member__c.Id}"}); 
alert("Approval has been recalled"); 
window.open('/{!Member__c.Id}'); 
} 
else 
{ 
alert("Recall Cancelled"); 
}