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
Amrita Panda 2Amrita Panda 2 

How to fetch public group associated with a queue using apex code?

Best Answer chosen by Amrita Panda 2
Khan AnasKhan Anas (Salesforce Developers) 
Hi Amrita,

Greetings to you!

You can do this by querying from the GroupMember object and accessing Group fields with the Grouprelationship.
 
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'

I hope it helps you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future.

Thanks and Regards,
Khan Anas