You need to sign in to do that
Don't have an account?
Recall Approval Process through Trigger
Hi , I am sending two approval processes though trigger.
When the Status__c of the Record is equal to 'Planning' Send the 1st Approval process.
When Status__c="Pending Approval" send the second approval process.
If I want to go from Pending Approval state to again to Planning I have to recall all the second Approval processes .
My code is :
trigger Submit_Approval_Process on Decision__c (after update) {
for(Decision__c thisdeci: Trigger.new){
Decision__c beforeUpdate = System.Trigger.oldMap.get(thisdeci.Id);
if(thisdeci.Status__c!=beforeUpdate.Status__c){
if( thisdeci.Status__c=='Planning' && thisdeci.Number_of_RACI_members__c >0){
List<Raci__c> allraci=new List<Raci__c>();
allraci=[select id,Name,NameofUser__c,decision__c,Ownerid,Approval_Status__c from Raci__c
where decision__c=:thisdeci.id ];
for(Raci__c r:allraci){
if(r.ownerid!=r.nameofuser__c){
Approval.ProcessSubmitRequest req=new Approval.ProcessSubmitRequest();
req.setComments('Submitting request for approval.');
req.setObjectId(r.id);
Approval.ProcessResult result = Approval.process(req);
System.assert(result.isSuccess());
}
}
}
}
if(thisdeci.Status__c!=beforeUpdate.Status__c){
if(thisdeci.Status__c=='Pending Approval'
&& thisdeci.Number_of_RACI_members__c >0 ){
List<Raci__c> allraci=new List<Raci__c>();
allraci=[select id,Name,Acknowledged__c,Informed__c,NameofUser__c,Approval_Status_on_Final_Decision__c,
decision__c,Approval_Status__c from Raci__c
where decision__c=:thisdeci.id ];
for(Raci__c r:allraci){
if(r.Informed__c==False && r.Approval_Status__c=='Approved/Accepted'){
Approval.ProcessSubmitRequest req1=new Approval.ProcessSubmitRequest();
req1.setComments('Submitting request for approval.');
req1.setObjectId(r.id);
Approval.ProcessResult result = Approval.process(req1);
System.assert(result.isSuccess());
}
}
}
}
}
}
Please help me on this, if anybody have an idea.