+ Start a Discussion
kkr.devkkr.dev 

How to retrieve User from a Queue

Hi All,

 

 

What i have Done is from GROUP object i retrieved records

List<Group> lstGroup = [select id,Type,Email,OwnerId,DoesSendEmailToMembers fromGroupwhere Type='Queue' and id='1234xxx']

 

Now from GroupMember Object retrived based on GroupID

list<GroupMember> lstGroupMember=[Select Id,UserOrGroupId, Group.NamefromGroupMemberwhere GroupId=:lstGroup [0].id];  

 

Now i need to retrive the user from that group.Any Thoughts

 

Thanks

Best Answer chosen by Admin (Salesforce Developers) 
Damien_Damien_
Set<Id> userIds = new Set<Id>();

for (GroupMember curr: IstGroupMember)
{
  userIds.add(curr.UserOrGroupId);
}

List<User> theUsers = [SELECT Id FROM User WHERE Id IN: userIds];

 

All Answers

Damien_Damien_
Set<Id> userIds = new Set<Id>();

for (GroupMember curr: IstGroupMember)
{
  userIds.add(curr.UserOrGroupId);
}

List<User> theUsers = [SELECT Id FROM User WHERE Id IN: userIds];

 

This was selected as the best answer
James LoghryJames Loghry

You can consolidate this from 3 queries to 2, actually:

 

List<GroupMember> lstGroupMember = [Select UserOrGroupId From GroupMember Where Group.Type='Queue' and GroupId=:groupId];

 

and then use Damien__c's logic to build the list of user ids to query once more.