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
vamsi krishna 106vamsi krishna 106 

How to get the Roles from Queue using Apex

I have queue,See below screen.
User-added image

and in the queue i have role, now i need to get the users based on that role ,please help me
 I tried like below 
select Id, type from Group where type='Queue' AND Name='Customer Service Director'
and see the result below
User-added image
Select Id,UserOrGroupId,GroupId,Group.type,Group.relatedid From GroupMember where GroupId='QueueId'

User-added image
but in the queue i have role not group i am getting the Group id(Please check the prefix of userorGroupid ,it's staring with 00G(Prefix of group)).Please help me to get the Roles from Queue,thanks in advance.
 
Anil MalneniAnil Malneni
Hi Vamsi..

we can get the list of users with role names from the queue. try this one..it may help you..

SELECT  UserRole.Name,Id,Name FROM  user  WHERE  id IN
( SELECT userOrGroupId FROM groupmember WHERE groupId ='Queue Id' )  
    ORDER BY  
         UserRole.name  


Thank you,
Anil
Rakesh51Rakesh51
You can do this by querying from the GroupMember object
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'