I need to get all members including members associated by their roles of a group passed in and am having trouble with the below code:
List<String> roleRelatedGroupIds = new List<String>();
for (Group g : [SELECT id, RelatedId, Type FROM Group where RelatedId= :UserInfo.getUserRoleId()]){
roleRelatedGroupIds.add(g.id);
}
List<String> allGroupIDs = new List<String>();
for (GroupMember gm : [SELECT Id, group.id, group.name, group.type FROM GroupMember where (UserOrGroupId = :UserInfo.getUserId() AND group.type='Regular') OR (UserOrGroupId IN :roleRelatedGroupIds AND group.type='Regular')]
{
allGroupIDs.add(gm.group.id);
}
}
I am hoping to be able to get all the members whether they are direct or indirectly associated by their roles, but my code will not compile in Developer console.
I am getting an error unexpected token '{'
on the line
for (Group g : [SELECT id, RelatedId, Type FROM Group where RelatedId= :UserInfo.getUserRoleId()]){
what am I doing wrong?
I am totally stuck just compiling my code before I find out if this is the right way to get all members of a public group as well as all members associated by their roles...