0

I want to check whether a user contains a certain public group. I have tried the following select statement

[SELECT id, Name FROM Group where RelatedId=: userInfo.getUserRoleId()
and DeveloperName  = *`<public group name>`* Limit 1]

But this does not return any record even though I have assigned the user into the public group.

0

1 Answer 1

1

Not Sure but Try something like this --- Might help you out in some way

Next we query the Group Member table for records where our user is specifically assigned and also include records where our role is assigned.

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);
}

Also go through this - Lengthy but nice one

Click Here

Not the answer you're looking for? Browse other questions tagged .