0

I am trying to find a count of users in all public groups in a salesforce org. Has anybody done any apex class which can get the results? Buyan

2 Answers 2

1

Execute the below code. You will get the answer.

List<group> groupRecList = [SELECT Id, Name, DeveloperName FROM Group WHERE Type = 'Regular';
Set<Id> SetOfUsers = new Set<Id>();
for (GroupMember GrpMem : [Select GroupId, UserOrGroupId From GroupMember Where GroupId IN :groupRecList]){
    if (GrpMem.UserOrGroupId.getSObjectType() == User.SObjectType)
        SetOfUsers.add(GrpMem.UserOrGroupId);
}
system.debug('SetOfUsers==>'+SetOfUsers.size());
0

You can query the GroupMember object. But don't forget to exclude Ids that start with the same prefix as groups (because groups can be referenced in other groups too).

You must log in to answer this question.

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