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
SabrentSabrent 

Querying for Group members of a public group

Can someone please point out why I am not getting anything in the map if i search by Group Name ?

 

 

// Get Id of the Group named Finance_Team

 

Map<Id, Group> groupMap = new Map<Id, Group>([
    Select Id, Name
    From Group
    Where Name = 'Finance_Team'
]);

 

// The above query doesn't return me the id of the group

 

 

 

//Find all members of the group

List<GroupMember> groupMembers = [
    Select GroupId, UserOrGroupId
    From GroupMember
    Where GroupId In :groupMap.keySet()
];

 

put the id's of the group members in a set

Set<Id> userOrGroupIds = new Set<Id>();
for (GroupMember member : groupMembers) {
    userOrGroupIds.add(member.UserOrGroupId);
}

 

Best Answer chosen by Admin (Salesforce Developers) 
swatKatswatKat

I think "Finance_Team" is the API name of your group ? In that case you need to query on the basis of the DeveloperName field like :

 

Map<Id, Group> groupMap = new Map<Id, Group>([
    Select Id, Name
    From Group
    Where DeveloperName = 'Finance_Team'
]);

All Answers

swatKatswatKat

I think "Finance_Team" is the API name of your group ? In that case you need to query on the basis of the DeveloperName field like :

 

Map<Id, Group> groupMap = new Map<Id, Group>([
    Select Id, Name
    From Group
    Where DeveloperName = 'Finance_Team'
]);

This was selected as the best answer
SabrentSabrent

Thanks!!! Much appreciated

 

Interesting though, Force.com explorer doesn't identify the field DeveloperName, whereas IDE does.