0

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
0

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;
                 }
                 else{
                 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>();
        if(publicGroup.size()>0){
            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){
          if(((String)m.UserOrGroupId).startsWith(userType)){
          userids.add(m.UserOrGroupId);
          }else if (((String)m.UserOrGroupId).startsWith(groupType)){

          groupIdProxys.add(m.userOrGroupId);

                    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'){
                                            roleId.add(g2.relatedId);
                                            system.debug('********:'+roleId);    
                                            }else if(g2.Type== 'RoleAndSubordinates'){
                                            roleAndSubId.add(g2.relatedId);  
                                            system.debug('********:'+roleAndSubId);   
                                            }else if(g2.Type== 'RoleAndInternalSubordinates'){
                                            roleAndSubId.add(g2.relatedId);
                                            system.debug('********:'+roleAndSubId);      
                                            }else if(g2.Type== 'Regular'){
                                            groupId.add(g2.id);    
                                            }
                                            system.debug(g2);
                                }
                if(roleAndSubId.size()>0){
                roleId.addAll(getAllSubRoleIds(roleAndSubId));
                }
                if(roleId.size()>0){

                  list<User> urs = [select id from user where UserRoleId IN: roleId];
                  for(User u: urs){
                    userids.add(u.id);
                  }
                }
                if(groupId.size()>0){

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

            }
         }

        }
       }else{
            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)
            currentRoleIds.add(userRole.Id);

        if(currentRoleIds.size() > 0)
          currentRoleIds.addAll(getAllSubRoleIds(currentRoleIds));

        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){
                                        Group_Name.put(u.UserOrGroupId,u.Group.Name);
                                        }   

                           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;
                           }else{
                           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"/>
                    </apex:actionfunction>
                    <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:selectList><br/><br/>
                    </div>
                     <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"/>
                                                </apex:pageBlockTable>
                                                </apex:pageBlockSection>
                      </apex:outputPanel>
</apex:pageBlock>
</apex:form>
</apex:page>
  • 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.