1

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...

1
  • 1
    @Ratan: no you solved it, thanks for your help...now I am trying to get all indirect members of a group associated through their roles by traversing the role hierarchy :) – Our Man in Bananas Mar 16 '16 at 9:28
1

You for loop is not closed.. You need to add ) at last

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')])
 {
    //rest code here
 }

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.