1

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,

  1. The approval process step updates the record
  2. The before trigger retrieves the pending approver and updates the same record.
  3. The process builder runs and updates certain fields on the record.
  4. 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

  • what is your actual usecase? – Santanu Boral Nov 26 '18 at 6:46
  • Usecase - User creates an Employee Bonus record and submits it for approval. The approval process has multiple approval steps where each step is assigned to an approver. The Employee Bonus object has a field called Pending Approver. The requirement is to update this field with the next pending approver (actorid) when a step in the approval process is complete. – Neema Nov 26 '18 at 15:39
  • To update pending approver as this is either user or queue which you have defined in the step so you can use process builder or workflow field update to update this field – Santanu Boral Nov 26 '18 at 18:43
  • on any approval step, I can only get the user or queue of that step and not the next immediate step. Not sure if I am missing something.. – Neema Nov 26 '18 at 20:27
0

I was able to resolve this by creating an apex InvocableMethod and calling this method from a process builder created on the Employee_Bonus object that runs on Employee_Bonus record create and Edit. When the Approval process step does a field update on the EMployee_Bonus record, the process builder runs, calls the apex method. Querying the StepsAndWorkItems at this stage populates the Pending Approver from the next step. This was missing in the BeforeUpdate trigger

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.