+ Start a Discussion
Subhrajyoti NathSubhrajyoti Nath 

Fetching of Approver name

User-added image


How to retrieve the Actual Approver name(i.e Subhra) in the visual force page for the quote as you can see from the image given above
Please help me write this query thanks in advance
Anirudh SinghAnirudh Singh
Hi Subhrajyoti,

Please find the below query, I think in this ActorId is the one that gives the Actual Approver Id.
SELECT Id, TargetObjectId, CreatedDate, LastActorId, (select id, ActorId from WorkItems )  from ProcessInstance
Once, you have the Id, Query on the User to fetch the Name.

Below code might help you:
//List of approval process records
List<ProcessInstance> approvalRecordsList=[
    SELECT Id, 
    (SELECT Id, ActorId, ProcessInstanceId FROM Workitems) 
    FROM ProcessInstance
];

//List of user Ids.
List<Id> RequiredUserIds = new List<Id>();

//Iterate and create a list of user ids.
for(ProcessInstance process: approvalRecordsList)
{
    List<ProcessInstanceWorkItem> pWorkItem = process.WorkItems;
    for(ProcessInstanceWorkItem pwi: pWorkItem)
    {
        RequiredUserIds.add(pwi.ActorId);
    }
}

//Fetch the User Name from User Ids List.
List<user> requiredUserList = [select Name from user where id =:RequiredUserIds ];

Please let me know if this helps.
If yes, please mark the Question as Solved.


Thanks and Regards,
Anirudh Singh
Amit Chaudhary 8Amit Chaudhary 8
Please try below code.
List<ProcessInstanceWorkItem> lst =  [SELECT Id, ActorId, ProcessInstanceId FROM ProcessInstanceWorkItem];

List<Id> RequiredUserIds = new List<Id>();

    for(ProcessInstanceWorkItem pwi: lst )
    {
        RequiredUserIds.add(pwi.ActorId);
    }

List<user> requiredUserList = [select Name from user where id =:RequiredUserIds ];

System.debug('----->'+requiredUserList);
Please check belpw post for Dynamic Approval Process in Salesforce using Apex and Trigger
http://www.jitendrazaa.com/blog/salesforce/dynamic-approval-process-based-on-the-apex-and-trigger/

Please let us know if this will help you

Thanks,
Amit Chaudhary
Subhrajyoti NathSubhrajyoti Nath
Thank you guyzz... Learnt some thing :)