You need to sign in to do that
Don't have an account?
How to prevent SOQL List from displaying duplicates?
Hi - I've created an SOQL query on the GroupMember object to query for all Queues that a user is not a member of. However, the list populates duplicates.
Does anyone know if the query can be setup to not display duplicates in my List? I've read that a loop may be possible, but I don't know how I would set it up to remove duplicates.
notqueueresults = new List<GroupMember> ([SELECT ID,Group.Name FROM GroupMember WHERE UserOrGroupId !=: results[0].Id ])
Thanks!
Does anyone know if the query can be setup to not display duplicates in my List? I've read that a loop may be possible, but I don't know how I would set it up to remove duplicates.
notqueueresults = new List<GroupMember> ([SELECT ID,Group.Name FROM GroupMember WHERE UserOrGroupId !=: results[0].Id ])
Thanks!
All Answers
Hi Justin,
Salesforce doesn't provide grouping in query result yet. I'm afraid you migth have to programmatically remove duplicates. One option is to fill up a set with group.name so that only unique values are stored:
You can do something like
Now that I'm looking at all the queue's in the org, I'm curious how there are multiple ID's for each GroupID. Is this the way Public Groups and Queue's share the GroupMembers object?
https://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_group.htm
List<Group> notqueueresults = new List<Group> ([SELECT Id, Name FROM Group where ID IN (select GroupID from GroupMember WHERE UserOrGroupId !=: results[0].Id) ])
Line 46, do you want to change the condition to UserOrGroupID "is NOT equal to" your chosen ID ? seems like you are checking if it is Equal. Can you add a "NOT" to it:
UserOrGroupId != : results[0].Id
Many thanks for everyone's help. Hopefully other people will find this useful as well.