I have an approval process with multiple steps. Each step updates the Employee_Bonus record. I have created a trigger on this object to capture the next pending approver using the stepsAndWorkItems. But the stepsAndWorkItems does not have the actorid of the next approver from the next approval process step. The stepsAndWorkItems still shows that the userid from the current step that approved as the pending approver. In the developer console, I can see all the steps including the actorid from the next approval process step.
Is this happenning due to the order of execution? I also have a process builder on this object that runs when a record is updated. So,
- The approval process step updates the record
- The before trigger retrieves the pending approver and updates the same record.
- The process builder runs and updates certain fields on the record.
- The before update trigger should execute again, correct? But it does not.
How can I work around this to retrieve the actorid from the next approval step?
trigger EBIEmployeeBonusTrigger on Employee_Bonus__c (before update) {
pendingApproverLst = [select id, targetobjectid, (SELECT actor.name,originalactorid,StepStatus FROM StepsAndWorkitems)
from ProcessInstance where targetobjectid in :trigger.newMap.keySet()];
for(ProcessInstance p: pendingApproverLst){
system.debug('The pending actor after '+ p.StepsAndWorkitems);
for(ProcessInstanceHistory h: p.StepsAndWorkitems){
if(h.StepStatus == 'Pending'){
trigger.newMap.get(p.targetobjectid).Pending_Approver__c= h.actor.name;
}
}
}
}
Somebody had a similar issue, which remains unanswered.. Approval Process - can't see approver in target object trigger