+ 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"); 
}