I have a requirement to design a Visual force page and controller where I need to display list of groups Of the particular group member or currently logged in user. I mean for a currently logged in user, only display those list of group names where he is the member of the group. i.e. Only the Groups the Member has joined should appear on the list of groups.

My VF Code is:

<apex:pageBlock id="pb1" mode="maindetail" title="Groups">
        <div id="div1" style="width=100; background-color:white; ">
            <apex:pageBlockTable value="{!Groups}" var="g" id="pbt1" align="top" style="border:none; border-style:none;">
            <apex:column style="vertical-align:top;width:0.5em;">
                       <apex:image value="{!$Resource.greydot}" height="1" width="1"/>
                <apex:column headerValue="" style="vertical-align:top;" headerClass="colHeadr">
                <input type="hidden" id="{!g.Name}" value="{!g.Id}"></input>
                <div id="row1data" onclick="redirect('{!g.Name}');" style="color:#16325C;font-weight: bold;">{!g.Name}</div>
                <div id="row2data" style="color:#16325C;"></div>


Apex Class:

public with sharing class GroupsController {

    Map<Id,StringGroups = new Map<Id,String>();
    Map<Id,StringGroupLists = new Map<Id,String>();
    public Map<Id,StringgetGroups()

        Set<IdGroupIds = new Set<Id>();
        for(CollaborationGroup g: [Select Id, Name, CollaborationType From CollaborationGroup WHERE IsArchived=false]){

        for(CollaborationGroupMember cgm : [SELECT Id,MemberId,CollaborationGroupId FROM CollaborationGroupMember WHERE CollaborationGroupId IN : GroupIds AND MemberId = :UserInfo.getUserId()]){
                System.debug('Member - '+cgm);
        return GroupLists;

  • What have you tried so far? It seems like you want someone else to work for you. Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.
    – Jarvis
    Commented Feb 23, 2016 at 12:27
  • I have written a vf page which displays list of group names for all user. I want the Group name list for a currently logged in user where the user is a group member. Those particular group names should need to be displayed in the page.
    – Sweta A
    Commented Feb 23, 2016 at 12:40
  • @SwetaA Please try the below query to achieve this. Commented Feb 23, 2016 at 12:46
  • Please paste your code for controller and VF page on your question.
    – Jarvis
    Commented Feb 23, 2016 at 12:48
  • 2
    @SwetaA After you paste code into a post, please select it and click on the pre-formatted code icon {} which moves every line over by 4 spaces so it will display properly. I've edited your post for you to do this.
    – crmprogdev
    Commented Feb 23, 2016 at 14:04

1 Answer 1


Please try the below query for getting the Group Names where current loggedin user is a member.

[select id, Group.Name from GroupMember where UserOrGroupId =: UserInfo.getUserId()]
  • Hi Nilesh.. I tried your code.. Can you please specify what else changes I need to do. I have shared my code in the question.
    – Sweta A
    Commented Feb 23, 2016 at 13:37
  • Are you referring chatter members? Commented Feb 23, 2016 at 13:42
  • If you are referring Chatter Group Member then you have use CollaborationGroupMember object instead of GroupMember(Child of Group). developer.salesforce.com/docs/atlas.en-us.api.meta/api/… Commented Feb 23, 2016 at 13:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .