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:page>
<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;">
<div>
<apex:image value="{!$Resource.greydot}" height="1" width="1"/>
</div>
</apex:column>
<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:column>
</apex:pageBlockTable>
</div>
</apex:pageBlock>
</apex:page>
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]){
if(g.Name!=null){
Groups.put(g.Id,g.Name);
GroupIds.add(g.Id);
}
}
for(CollaborationGroupMember cgm : [SELECT Id,MemberId,CollaborationGroupId FROM CollaborationGroupMember WHERE CollaborationGroupId IN : GroupIds AND MemberId = :UserInfo.getUserId()]){
if(Groups.containsKey(cgm.CollaborationGroupId)){
GroupLists.put(cgm.CollaborationGroupId,Groups.get(cgm.CollaborationGroupId));
System.debug('Member - '+cgm);
}
}
return GroupLists;
}
}
{}
which moves every line over by 4 spaces so it will display properly. I've edited your post for you to do this.