public class getUserListClass {
public static List<User> getUserList(String GroupId){
List<GroupMember> GroupMemberList1 = [SELECT Id, GroupId, UserOrGroupId, Group.Name FROM GroupMember WHERE Group.Id =: GroupId ];
Set<Id> UserIdSet = new Set<Id>();
Set<Id> GroupIdSet1 = new Set<Id>();
Set<Id> GroupIdSet2 = new Set<Id>();
Set<Id> GroupIdSet3 = new Set<Id>();
for (GroupMember GM1 : GroupMemberList1) {
String id_str = (String)GM1.UserOrGroupId;
if (id_str.left(3) =='005') {
UserIdSet.add(GM1.UserOrGroupId);
} else {
GroupIdSet1.add(GM1.UserOrGroupId);
}
}
if ( GroupIdSet1.size() >0) {
List<GroupMember> GroupMemberList2 = [SELECT Id, GroupId, UserOrGroupId, Group.Name FROM GroupMember WHERE Group.Id =: GroupIdSet1];
for (GroupMember GM2 : GroupMemberList2) {
String id_str = (String)GM2.UserOrGroupId;
if (id_str.left(3) =='005') {
UserIdSet.add(GM2.UserOrGroupId);
} else {
GroupIdSet2.add(GM2.UserOrGroupId);
}
}
if ( GroupIdSet2.size() >0) {
List<GroupMember> GroupMemberList3 = [SELECT Id, GroupId, UserOrGroupId, Group.Name FROM GroupMember WHERE Group.Id =: GroupIdSet2];
for (GroupMember GM3 : GroupMemberList3) {
String id_str = (String)GM3.UserOrGroupId;
if (id_str.left(3) =='005') {
UserIdSet.add(GM3.UserOrGroupId);
} else {
GroupIdSet3.add(GM3.UserOrGroupId);
}
}
}
}
List<User> UserList = new List<User>();
if( UserIdSet.size() >0) {
UserList = [SELECT Id FROM User where Id =: UserIdSet];
}
return UserList;
}
}
- Open excute anonymous window
Use 18 digit Id
List<User> UserList = getUserListClass.getUserList('00G2x000000uOKDEA2');
IF(UserList.size() >0 ){
for (User u : UserList){
system.debug(Logginglevel.INFO,'-- List --> '+ u.Id );
}
}
- Final result