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

Output:


