Search code examples
salesforceapexsoql

soql query to get list of queue/group names assigned to user


I am working on a query to get the names of each queue a user is in with a binding variable but am running into some issues with pulling both the queue and group.

query:

public static List<Group> getQueues(String recordId){
        return [SELECT Name FROM Group WHERE Id IN (SELECT GroupId FROM GroupMember WHERE 
        UserOrGroupId = :recordId)];
    }
}

This works without issue but pulls both the group and queues. I am looking to only pull the queue.

Any suggestions on how I can modify the query to only get queues?


Solution

  • Resolved for groups with:

    public static List<Group> getQueues(String recordId){
    
            return [SELECT Name, Type FROM Group WHERE Type = 'Regular' AND Id IN (SELECT GroupId FROM GroupMember WHERE UserOrGroupId = :recordId)];
        }
    }
    

    Resolved for queues with:

    public static List<Group> getQueues(String recordId){
    
            return [SELECT Name, Type FROM Group WHERE Type = 'Queue' AND Id IN (SELECT GroupId FROM GroupMember WHERE UserOrGroupId = :recordId)];
        }
    }