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? 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

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.

enter image description here


Visualforce Page Code

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

Apex Code

public class GroupsController {
    public String selectedVal{
        get{return selectedVal;}set{selectedVal= value;}
    public String selectedVal1{
    public List<SelectOption> users_id {
         get{return users_id;}
    public PageReference setmyValue(){
         List<GroupMember> gm = [SELECT userorgroupid from GroupMember where groupid=:selectedVal];  
         List<String> group_id  = new  List<String>();
         for(GroupMember g:gm){
         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();
                        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){
                g1roupsList.add(new SelectOption(g.id,g.developername));
            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.