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
visualforce_devvisualforce_dev 

Approvals in vf page

Hi,

 

I want all records pending for my approval for a particular object in a table,

 

how can I do  it in simple way? All standard objects supporting approval process have record id. But how can I get the object .

 

for e.g... Custom objects 'A 'and 'B ' have approval process..

 

in my  page I want only records from 'A' awaiting my approval..

 

Thanks in advance

 

rcravenrcraven

I've used the following code to create a list of items to approve for a given object.  However, it's based on matching object related records which have active workitems rather than just based on the object itself.  Let me know if you find a better way to link it to the object rather than the object records?

 

 

//populate list of approval items private List<ProcessInstanceWorkitem> lstApprovalItems;

private List<Id> memberOfQueue = new List<Id>();

 

List<GroupMember> groupMembers = [Select Group.Id From GroupMember where UserOrGroupId = :UserInfo.getUserId() and (Group.Name in : config.get('ApprovalProcessQueues').split(',')) Limit 10];

//list queue ids current user is a member of
if(groupMembers.size() > 0){
for(GroupMember g : groupMembers){
memberOfQueue.add(g.Group.Id);
}
}  

lstApprovalItems = [select p.id, p.ProcessInstance.TargetObjectId, p.ProcessInstanceId, p.OriginalActorId From ProcessInstanceWorkitem p where IsDeleted = false and (p.OriginalActorId =: UserInfo.getUserId() or p.OriginalActorId in :memberOfQueue) and p.ProcessInstance.TargetObjectId in (select id from Ticket_Data_Form__c where recordtypeid =: config.get('DF_RecordTypeId') and Approval_Status__c != 'Approved' and Approval_Status__c != 'Rejected' Limit 1000)];

 

 You could alternatively use a subquery to match on the first three letters of the salesforce object record id values.

 

(select id from Ticket_Data_Form__c where id.substring(0, 3) = 'cON' and Approval_Status__c != 'Approved' and Approval_Status__c != 'Rejected' Limit 1000)

 * Note this works well if approval process is assigned to a user or queue.  However, if queue, the queue assignment needs to be associated to actual users (not roles, roles and subordinates, etc)  You would need to update the code to find if current user is member of queue based on role assignments. (if you update please let me know).

 

 

 

 

 

 

visualforce_devvisualforce_dev
Thanks a lot, i will let u know if I got any bettr solution...
tstrongtstrong
Could you please also post your VF page code?  I'm trying to write a VF page for the standard Items to Approve list with some additional fields added to it and just wanted to see how others have done it.