The trigger below is built to pull the most recent "assigned to" user (or OriginalActorId
) from the approval process list, the Approval_started__c
field is checked as an initial submission action from a specific approval process.
The issue I have is that the system.debug statement below is not showing the most recent assigned to user in the last pending Approval request but shows the most recent request assigned to user before the user clicks on submit for approval, so it skips the "approval request submitted step" that the User did when he clicked on Submit for approval and the initial submission action pending Step (where the approver is selected by the user) which is pending approval/rejection and it returns the old request that was right before these 2.
My goal it to pull the latest pending request "assigned to" user or OriginalActorId
value.
Any thoughts ? Thanks.
Here's a screenshot of the approval process list, with in black the value I fetch with this trigger on the debug log line and in blue the expected value.
trigger Assigned2testTrigger on LLC_BI__Product_Package__c(after update) {
list < LLC_BI__Product_Package__c > listpp = new list < LLC_BI__Product_Package__c > ();
for (LLC_BI__Product_Package__c pp: trigger.new) {
If(!checkRecursive.SetOfIDs.contains(pp.Id)) {
if (pp.Approval_started__c == true) {
system.debug('---------> My ProcessInstance ' + string.valueof([Select Id, (Select TargetObjectId, SystemModstamp, StepStatus, RemindersSent, ProcessInstanceId, OriginalActorId, IsPending, IsDeleted, Id, CreatedDate, CreatedById, Comments, ActorId From ProcessSteps order by SystemModstamp desc) from LLC_BI__Product_Package__c where Id =: pp.id].ProcessSteps[0].OriginalActorId));
}
checkRecursive.SetOfIDs.add(pp.Id);
}
}
}