We need to first display all public groups in a picklist format. Then we need select one user from that list. Now how to display the group members in the form of table format? can anyone help me....

  • Public group can have roles, portal and internal subordinates, groups and individual users. Do you want to list individuals or roles, portal and internal subordinates, groups ? – SL man Oct 30 '15 at 5:06
  • Hi SL man,Yes ,i want once select the Public Group then dispaly individuals the public Group members name,username,Role,Profile,active fields in the form of table format – Test New Oct 30 '15 at 6:04
  • @TestNew I think here you can find some ideas how to do it – kurunve Oct 30 '15 at 8:04

i think some ideas and got the output but i want after display the public group members table format then download excel format..i tried this below code but here display the all users data..my problem is how to download only public group member users table for excel format? can anyone help me

Controller :

public with sharing class Publicgroup
  public boolean isExport {get; set;}
  public List<Group> publicGroup;
  public string groupId {get; set;}
  public boolean gettable {get; set;}
  public static set<id> userids = new set<id>();
  public  Map<ID,String> Group_Name {get;set;}

  public Publicgroup(ApexPages.StandardController controller) 
    Group con = (Group)controller.getRecord();
                 if(Apexpages.currentPage().getParameters().get('Export') != null){
                 isExport = true;
                 isExport = false;
    publicGroup = [SELECT Id, Name FROM Group WHERE Type = 'Regular'];
    System.Debug('Public group :'+publicGroup); 


  public List<SelectOption> getgrouplist() {

        List<SelectOption> options = new List<SelectOption>();
            options.add(new SelectOption('','------- Select Public Group --------')); 

            for (Group gr : publicGroup){
                options.add(new SelectOption(gr.Id,gr.name ));
        return options;

     public void GetGroupMembers()
       System.debug('GroupID :'+ groupId);

        String userType = Schema.SObjectType.User.getKeyPrefix();
        String groupType = Schema.SObjectType.Group.getKeyPrefix();
        Set<Id> groupIdProxys = new Set<Id>();

        if(groupId != null && groupId != ''){ 
        gettable= true;

          List<GroupMember> GroupMembers = [select UserOrGroupId,Group.Name from GroupMember where GroupId =:groupId];
          for(GroupMember m:GroupMembers){
          }else if (((String)m.UserOrGroupId).startsWith(groupType)){


                    if(groupIdProxys.size() > 0){
                        Set<id> groupId = new set<id>();
                        Set<id> roleId = new set<id>();
                        Set<id> roleAndSubId = new set<Id>();

                        List<Group> publgroup = [Select Id, Type, relatedId From Group Where Id = :groupIdProxys];
                                for(Group g2 : publgroup){

                                    if(g2.Type == 'Role'){
                                            }else if(g2.Type== 'RoleAndSubordinates'){
                                            }else if(g2.Type== 'RoleAndInternalSubordinates'){
                                            }else if(g2.Type== 'Regular'){

                  list<User> urs = [select id from user where UserRoleId IN: roleId];
                  for(User u: urs){

                    list<GroupMember> gmr = [select id, UserOrGroupId from GroupMember where GroupId IN: groupId];
                        for(GroupMember gm1 :gmr ){


            gettable= false;
            groupid = '';

     public static Set<ID> getAllSubRoleIds(Set<ID> roleIds) {

        Set<ID> currentRoleIds = new Set<ID>();
        List<UserRole> urole = [select Id from UserRole where ParentRoleId IN :roleIds AND ParentRoleID != null Limit 40000];

        for(UserRole userRole :urole)

        if(currentRoleIds.size() > 0)

        return currentRoleIds;


     public list<user> getUsers() {

        List<GroupMember> GroupMembers1 = new List<GroupMember>();
                             GroupMembers1 = [select UserOrGroupId,Group.Name from GroupMember where GroupId =:groupId];
                                     Group_Name = new Map<ID,String>();
                                        for(GroupMember u :GroupMembers1){

                           list<user> u = new list<user>();
                           u= [select id,name,username,email,UserRole.name,profile.name,isActive from user where id in:userids and IsActive = true];
                           if(u.size() >0){
                           return u;
                           return null;

     public PageReference export(){

                 isExport = true;
                 return null;


Visualforce page :

<apex:page standardController="Group" extensions="Publicgroup" sidebar="{!!isExport}" showHeader="{!!isExport}" standardStylesheets="false" contentType="{!IF(isExport = true, 'application/vnd.ms-excel#report.xls', '')}">
<apex:form id="theform"><br/><br/>
<apex:pageBlock >
<apex:actionFunction action="{!getGroupMembers}" name="PublicGroups">
                    <apex:param assignTo="{!groupid}" value="Group"/>
                    <div >
                                    <apex:outputText value="Public Groups:  " />
                                    <apex:selectList value="{!Groupid}" multiselect="false" size="1" onchange="PublicGroups(this.value)" id="Group">
                                    <apex:selectOptions value="{!grouplist}" />
                                    <apex:actionSupport event="onchange" status="thestatus" reRender="resTable"/>
                     <apex:outputPanel id="resTable">
                     <apex:commandButton action="{!export}" value="Export" rendered="{!AND(isExport = false, users.size != 0)}" reRender=""/><br/> <br/>
                     <apex:pageBlockSection title="Group Members">
                     <apex:pageBlockTable value="{!users}" var="u"  rendered="{!(users.size != 0)}">
                                                <apex:column headerValue="Group Name" value="{!Group_Name[u.id]}"/>
                                                <apex:column value="{!u.name}" headerValue="Name" />
                                                <apex:column value="{!u.userrole.name}" headerValue="Role"/>
                                                <apex:column value="{!u.profile.name}" headerValue="Profile"/>
                                                <apex:column value="{!u.username}" headerValue="UserName"/>
                                                <apex:column value="{!u.Email}" headerValue="Email"/>
  • You are returning a null pagereference and using rerender="" in the button. Essentially nothing is rerendered. I also do not believe the page is in an excel exportable format. Desperate the excel page and use params to give it what it needs to get the right data – Eric Mar 28 '17 at 8:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.