+ Start a Discussion

How to find the approvers for outstanding approval process instances?

The code below is my first attempt at solving this problem based on inspecting the relevant objects via the developer console. But I have not found any documentation that confirms that this logic is appropriate. Please comment if you now of such documentation or have a cleaner or proven solution.






// Return payment id to set of approver ids
private Map<Id, Set<Id>> readApprovers(Set<Id> paymentIds) {
    // Get the latest ProcessInstance for each payment
    Map<Id, ProcessInstance> m = new Map<Id, ProcessInstance>();
    for (ProcessInstance pi : [
            select Id, TargetObjectId, (select ActorId from Steps where StepStatus not in ('Approved', 'Rejected'))
            from ProcessInstance
            where TargetObjectId in :paymentIds
            and IsDeleted != true
            and Status not in ('Approved', 'Rejected')
            order by CreatedDate desc
            ]) {
        if (m.get(pi.TargetObjectId) == null) {
            m.put(pi.TargetObjectId, pi);
    // Ensure always at least an empty set not null
    Map<Id, Set<Id>> results = new Map<Id, Set<Id>>();
    for (Id paymentId : paymentIds) {
        results.put(paymentId, new Set<Id>());
    // Find any actors who have not processed their step
    for (ProcessInstance pi : m.values()) {
        for (ProcessInstanceStep pis : pi.Steps) {
            if (pis.ActorId != null) {
    return results;



I have a great write up on how to automatically email the current approver here. for outstanding approval requests only of course.

@colmab Is there an updated link for your article? The linked URL won't load fully.