How to create a map of Group and GroupMembers apex salesforce - Salesforce Globe For You
Run the following piece of code in anonymous window.
Map<Group,List<GroupMember>> mapGroupGroupMembers = new Map<Group,List<GroupMember>>();
for(Group objGroup : [Select id,name,(select id,UserOrGroupId from GroupMembers) from Group]) {
List<GroupMember> lstGroupMembers = new List<GroupMember>();
if(!objGroup.GroupMembers.isEmpty()) {
for(GroupMember objMember : objGroup.GroupMembers) {
lstGroupMembers.add(objMember);
}
mapGroupGroupMembers.put(objGroup,lstGroupMembers);
} else {
mapGroupGroupMembers.put(objGroup,lstGroupMembers);
}
}
system.debug('mapGroupGroupMembers:'+mapGroupGroupMembers);
Output:
No comments:
Post a Comment