8

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? Commented Jun 18, 2014 at 12:46

1 Answer 1

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
  • 4
    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
    Commented Jul 26, 2017 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. Commented Jan 8, 2018 at 16:49
  • Did you find any solution for this problem? @JonDuelfer @ Bigears
    – Enry
    Commented Mar 3, 2018 at 15:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .