The trigger given below is built to pull the most recent 'assigned to' user (or OriginalActorId) from the approval process list. The Approval_started__c field is ticked off as an initial submission action from a specific approval process.
My issue 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 has done by clicking 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 here is to pull the latest pending request "assigned to" user or the OriginalActorId value.
Any thoughts? Thanks.
Here, I am providing a screenshot of the approval process list. Given in black is the value I fetched with this trigger on the debug log line, and given in blue is 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);
}
}
}