function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
newbee developernewbee developer 

SOQL Query to get loggedin user's items to approve

Hi All,

I want to fetch items which loggedin user can approve and display in a pageblocktable.
Below is my code written so far -

   set<Id> setOfKnowledgeArticleId = new set<Id>();
   set<Id> setOfProcId= new set<Id>();
    
   //Below code gets pending items from ProcessInstance.
    listOfPending = [SELECT Id, TargetObjectId, Status, LastModifiedDate FROM ProcessInstance where Status='Pending' ORDER BY                                                 LastModifiedDate DESC ];
   for(ProcessInstance ProcessInstanceObj:listOfPending )
   {
        //Getting TargetObjectId to query Title,Summary from Custom Object and display in table
        setOfKnowledgeArticleId.add(ProcessInstanceObj.TargetObjectId);     
        // IDs to query the actor ID
        setOfProcId.add(ProcessInstanceObj.Id);        
   }
  
   
   listOfActors = [SELECT Id, ActorId FROM ProcessInstanceWorkitem  where Id IN: setOfProcId ];
   set<Id> setOfActId= new set<Id>();
   for(ProcessInstanceWorkitem pwObj:listOfActors  )
   {
        setOfActId.add(pwObj.Id);     
       
   }
   setOfActId is empty here, even though i know it should not be empty.

Please suggest how to achieve this. 
Rahul KumarRahul Kumar (Salesforce Developers) 
Hi,

May I suggest you please refer the below link for reference. hope it helps.

Please mark it as best answer if the information is informative.so that question is removed from an unanswered question and appear as a proper solution.

Thanks
Rahul Kumar
Salesforce TechieSalesforce Techie
https://thesalesforcetutorial.blogspot.com/2022/09/query-items-to-approve-insalesforce.html