I'm working on a Dual Picklist where in left column I need to show a list of Queues where a selected user belongs to and in the right column a list of Every Queue that exist on the org besides the Queues that belong to the selected user.

Queues from the ORG Arrows Queues from User
All queues from org excluding the Queues from selected User add> & OR <remove Queues from selected User

However I'm struggling to show the Queues from the Org where the User doesn't belong to, with the query: select id, groupId,group.Name, group.Type from GroupMember where userorGroupId !='00509000007qMJHAA2' and group.type='queue'I get in return the queues where this person belongs to, but because that Queue belongs to other users too. To show the Queues where the user belongs to I am using the following queue in Apex class

@AuraEnabled (cacheable=true)
public static List<GroupMember>getGroups(string userId, string type){
    List<GroupMember> groupList = new List<GroupMember>();
    if(userId !=''){
        String userIdModal= userId;
        groupList=[select id, groupId,group.Name from GroupMember where userorGroupId !=:userIdModal and group.type=:type];
        return groupList;
    return groupList;

and my JS looks like this

@track showModal = false;
@track dataShow;
@api selectedUser;

@wire (getGroups,{userId:'$selectedUser', type:'queue'})
    retrieveGroups ({error, data}) {
       if (data) {
        }else if(error){
            console.log('Sorry,nothing was found');

//use @api because we are accesing info from a parent component
    @api show(){




This can quickly get more difficult depending on your need. The reason is explained well with this question (Get all queue users), but it comes down to the fact that there's other ways users may be part of a queue without them explicitly being a GroupMember:

  • User Role
  • User Role & Subordinates
  • Other Public Groups (ex. All Internal Users)

I'm going to assume you're only leveraging/assigning users directly into queues for your use case. In that case, the problem with your query is that you looking at GroupMember which pulls all members across all queues.

You'll want to take a different approach for your SOQL query. What you attempted is just going to give you every GroupMember that isn't your user which would be any Group that has "other" members - which could be queues they're apart of or not.

  1. Get Queues the User is not explicitly assigned to (as a GroupMember):
FROM Group 
WHERE Type = 'Queue' AND ID NOT IN 
(SELECT GroupId FROM GroupMember WHERE UserOrGroupId =: userIdModal) 
  1. Get Queues the User is explicitly assigned to (as a GroupMember):
FROM Group 
WHERE Type = 'Queue' AND ID IN 
(SELECT GroupId FROM GroupMember WHERE UserOrGroupId =: userIdModal)

The where criteria in both queries above specifically excludes or includes those groups whose group Id is found in the query against GroupMember looking for your specific user.


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.