Apex code : ApprovalRecall
global class approvalRecall
{
webservice static void recallApproval(Id recId)
{
system.debug('recId****'+recId);
NST__c[] nsts = [SELECT Id,NST_Status__c from NST__c WHERE Id=:recId];
ID ObjectId=recId;
List<ProcessInstance> pi = new List<ProcessInstance>([SELECT Id FROM ProcessInstance WHERE TargetObjectId =: ObjectId ]);
if( (pi.size()==0))
{
for(NST__c nst : nsts )
{
nst.NST_Status__c='Draft';
update nst;
}
}
else
{
List<ProcessInstanceWorkitem> piwi =new List<ProcessInstanceWorkitem>( [SELECT Id FROM ProcessInstanceWorkitem WHERE ProcessInstanceId=: pi[0].id]);
if((piwi!=null ) && (piwi.size()>0))
{
Approval.ProcessWorkitemRequest req = new Approval.ProcessWorkitemRequest();
req.setAction('Removed'); // steps to recall the approval process
req.setWorkitemId(piwi.get(0).Id);
Approval.process(req,false);
}
// Unlock the NST
Approval.UnlockResult[] urList = Approval.unlock(nsts, false);
for(NST__c nst : nsts )
{
nst.NST_Status__c='Draft';
update nst;
}
}
This apex class is working when the record owner and Admin clicks the "Submit for Approval" and both can view the "Recall" button and access the process. But other than record owner and admin i.e., user unable to view the recall button when the record owner or Admin clicks the "Submit for Approval".
My requirement is " whoever submit the approval, all user should recall the approval process.Could you please assist me to fix this issue.Please let me know if you need any other information.Thanks in advance!!!RegardsSivapriyaa M SI did not find a Saleforce topic for this, but i am sure there is one.
Heres an idea from stackexchange by setting up an email service to do this as non owner.