0

How to display Public groups in drop down list and in this list select one public group,then search button clicks need to display the users in particular public group? anybody help me......

  • I'm afraid this forum is not there to provide you with a full code solution. We can however help with specific problems that you have while trying. What did you try so far? Any code examples? – Guy Clairbois Oct 23 '15 at 9:52
  • Hey Guy, i had tried so many examples.so far i didnt get the answer.that why i post the question. i am new to practicing the visualforce pages. – user Oct 23 '15 at 9:58
  • I will try to help, give me some time. I will try to develop solution for you – Ajay Gupta Oct 23 '15 at 10:00
  • I think you can check here salesforce.stackexchange.com/questions/96643/… is some description how to get users for group – kurunve Oct 23 '15 at 10:25
0

To display Public groups in drop down list and in Available Public Groups list select one public group,then press List Users button. After pressing the List Users button, you will get the all Available Users associated with that groups as shown in below screen shot as well.

Output:
enter image description here

Code:

Visualforce Page Code

<apex:page controller="GroupsController" >
    <br/>
    <div style="padding:30px;">
        <apex:form >
            <div style="text-align:center;">
                <b style="padding-bottom:15px;">Available Public Groups</b>
                <br/>
                <apex:selectList value="{!selectedVal}" size="10" style="width:305px;">
                    <apex:selectOptions value="{!groupsList}"/>
                </apex:selectList>
            </div>
            <br/>
            <center><apex:commandButton action="{!setmyValue}" reRender="textDisplay" value="List Users"/></center>
            <br/>
            <div style="text-align:center;">
                <b style="padding-bottom:15px;">Available Users</b>
                <br/>
                <apex:outputPanel id="textDisplay">
                    <apex:selectList value="{!selectedVal1}"  size="10" style="width:305px;">
                        <apex:selectOptions value="{!users_id}"/>
                    </apex:selectList>
                </apex:outputPanel>
            </div>
        </apex:form>
    </div>  
</apex:page>

Apex Code

public class GroupsController {
    public String selectedVal{
        get{return selectedVal;}set{selectedVal= value;}
    }
    public String selectedVal1{
    get;set;
    }
    public List<SelectOption> users_id {
         get{return users_id;}
         set{users_id=value;}
    }
    public PageReference setmyValue(){
         List<GroupMember> gm = [SELECT userorgroupid from GroupMember where groupid=:selectedVal];  
         List<String> group_id  = new  List<String>();
         for(GroupMember g:gm){
              group_id.add(g.userorgroupid+'');
         }
         List<USER> users_1  = [SELECT name from User where id in :group_id];
         users_id = new List<SelectOption>();
          for(User u:users_1 ){
              users_id.add(new SelectOption(u.name,u.name));
         }
        return null;
    }
    public List<selectOption> getGroupsList(){        
            SET<String> fields = new SET<String>();
                        fields = Schema.SObjectType.Group.fields.getmap().keyset();
                        System.debug(fields);
                        List<Group> groups = [select developername,name, type from group where type= 'Regular'];
                        Map<id,Group> group_maps = new Map<id,Group>();
                        List<selectOption> g1roupsList = new List<selectOption>();
            for(Group g :groups){
                        group_maps.put(g.id,g);
                g1roupsList.add(new SelectOption(g.id,g.developername));
                        }
                        System.debug(group_maps);
            return g1roupsList;
    }
}

Try the code and do practice, you may also modify the code as per your requirement. I hope my answer will help you. Thanks!!

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.