0

I need to generate a spreadsheet of all members of all queues [whether individual users or Public Groups..we don't use Roles], with columns similar to this:

Queue ID, Queue Name, Member Name, Member Id, Public Group, Public Group Id

There do not seem to be any report types for this, so I'm assuming SOQL is my best option?

Searching this forum, it seems that this is more difficult that it should be....Any thoughts on how to acheive this?

2
  • 1
    a queue member can be a public group which in turn can have public group members that in turn can also be comprised of public group members, and so on. At any level there can be individual user members of the queue or public group. If you want to explode this tree, you'll need apex+soql
    – cropredy
    Jun 22 at 19:08
  • In my case, I'd be happy with simply the current direct membership: I.e., list of all public groups and individuals directly associated with each queue [essentially, what you see on the Setup screen, when Editing each queue]. Is there a more straightforward way to get to just that?
    – Bob Mount
    Jun 23 at 20:34
0

Reference: Users, Groups and Sharing Schema

what one would like to be able to do is this:

SELECT Id, Name,  (SELECT id, UserOrGroupId, UserOrGroup.Name 
                     FROM GroupMembers)
  FROM Group 
  WHERE Type = 'Queue'

but sadly, as of V52, the UserOrGroup relationship name is not available to SOQL. This restriction also means you can't do this:

SELECT Id , (SELECT Id, TYPEOF UserOrGroup 
                          WHEN User THEN Name 
                          WHEN Group THEN Name 
                         END 
               FROM GroupMembers) 
  FROM Group 
  WHERE Type = 'Queue'

So, you'll need some Apex, three queries, and two passes

Group[] groupsWithMembers = [SELECT Id, Name,  (SELECT Id, UserOrGroupId
                 FROM GroupMembers)
             FROM Group 
             WHERE Type = 'Queue'];

Set<id> userIds = new Set<Id>();
Set<Id> groupIds = new Set<Id>();

// Pass 1 - get member ids
for (Group gwm: groupsWithMembers) {
   for (GroupMember gm: gwm.GroupMembers) {
     if (gm.UserOrGroupId.getSobjectType == User.SObjectType) {
        userIds.add(gm.UserOrGroupId);
     }
     else {
         groupIds.add(gm.UserOrGroupId);
     }
 }

 Map<Id,User> usersById = new Map<Id,User> ([SELECT Id, Name From User
                                                WHERE Id IN :userIds]); 
 Map<Id,Group> groupsById = new Map<Id,Group> ([SELECT Id, Name From Group
                                                WHERE Id IN :userIds]); 


// Pass 2 - build report
for (Group gwm: groupsWithMembers) {
   for (GroupMember gm: gwm.GroupMembers) {
     if (gm.UserOrGroupId.getSobjectType == User.SObjectType) {
        User u = usersById.get(gm.UserOrGroupId);
        // display line here using gwm, and u
     }
     else {
         Group g = groupsById.get(gm.UserOrGroupId);
        // display line here using gwm, and g

     }
 }

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.