0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

How to get the group members user details (Like user id, username) from Data loader?

Last updated at Posted at 2022-04-12
  • Create an Apex class.
    image.png

  • The Apex class name is getUserListClass.
    image.png

  • Copy and paste the following.

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

image.png

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

image.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?