function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ShitalShital 

Group, Group member and User

Hello Guys,

Hope you all are safe!!

I want to show users name and when the user is added to particular group on lighting page.
First part I am able to display users name and to display users added date I need your help

This code is showing all the users added in public group/Queue so along with this name of users I would like to show when the user is added to grp/queue

public with sharing class HRM_GetQueueMembers_ctlr {   
    @AuraEnabled
    public static List<Group> getQueue(){ //this function fetches all the queues
        List<Group> QueueList = [Select Name,CreatedDate from Group where type='Queue' and DeveloperName like 'HRM%' ORDER BY Name ASC];
        system.debug('---QueueList'+QueueList);
        return QueueList;
    }
    
    @AuraEnabled
    public static List<User> getQueueMembers(Id QueueId){ //this function fetches queue members        
        List<GroupMember> publicGroupList = [Select UserOrGroupId from GroupMember where GroupId=:QueueId];
        system.debug('---publicGroupList'+publicGroupList);
        List<Id> listGroupId = new List<Id>();
        List<User> MemberList = new List<User>(); 
        List<Id> listOfUsersId=new List<id>();
        
        try{
            for(GroupMember gm:publicGroupList){                
                string mId = gm.UserOrGroupId;
                if(mId.left(3)=='005'){ //If first 3 char of UserOrGroupId are '005' then it is a user
                    listOfUsersId.add(mId);
                }else if(mId.left(3)=='00G'){ //If first 3 char of UserOrGroupId are '00G' then it is a group
                    listGroupId.add(mId);
                }
            }
            
            //while(listGroupId.size()>0)
             //This loop will run untill there are public groups inside public groups(removed while loop due to sonar cube issue)
                List<GroupMember> MemberIds = [Select UserOrGroupId,SystemModstamp from GroupMember where GroupId=:listGroupId];
                listGroupId.clear();
               
                for(GroupMember m : MemberIds){
                    string mId = m.UserOrGroupId;
                   
                    if(mId.left(3)=='005'){ //If first 3 char of UserOrGroupId are '005' then it is a user
                        listOfUsersId.add(mId);
                        //listofUsersId.add(D);
                    }else if(mId.left(3)=='00G'){ //If first 3 char of UserOrGroupId are '00G' then it is a group
                        listGroupId.add(mId);
                    }
                }
            
             
            if(listOfUsersId.size()!=0){
                List<User> u = [Select Name, profile.Name, UserRole.Name from User where Id in:listOfUsersId ];
                if(u.size()>0){
                    MemberList.addAll(u);
                } 
            }
        }
        catch(Exception e){
            e.getStackTraceString();
        }
        return MemberList;
    }
}

Any thoughts or help will be much appriciated!!