7

I would like to query all hardcodequeue groups I am a member of. So far it seems I can only query a queue if I hard-code it's name. There doesn't seem to be a way to query a queue and have it return if memberId=:someUserID

List<Id> qId = [select id from Group where type='Queue' AND Name='Test Queue']; //gives queue with the name test queue
List<Id>userID = [select UserOrGroupId from GroupMember where GroupId IN:qid]; //gives users in groups
1
  • Did my answer point you in the right direction with this? – Alex Tennant Jun 18 '14 at 12:46
9

You can do this by querying from the GroupMember object and accessing Group fields with the Group relationship.

SELECT 
    Group.Name
FROM 
    GroupMember 
WHERE 
    UserOrGroupId = 'YOUR-USER-ID' 
    AND Group.Type = 'Queue'

If you want to check if a user is a member of a specific Queue then you can use the following query and if it returns null then they are not a member of that queue.

SELECT 
    Group.Name
FROM 
    GroupMember 
WHERE 
    UserOrGroupId = 'YOUR-USER-ID' 
    AND Group.Type = 'Queue'
    AND Group.Name = 'YOUR-QUEUE-NAME'
3
  • 3
    My understanding is that this will only work where a user is a "direct" member of the queue. Where the queue membership includes Roles, Roles and subordinates or other public groups, this approach will not work. I bring this up because I'm looking for a solution to this problem at the moment! – Bigears Jul 26 '17 at 11:22
  • I agree with Bigears, I currently have a Queue that contains Roles and Subordinates, but this was not working. I had to add each user to the queue individually. – Jon Duelfer Jan 8 '18 at 16:49
  • Did you find any solution for this problem? @JonDuelfer @ Bigears – Enry Mar 3 '18 at 15:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.