function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Swetha A 5Swetha A 5 

Display List of chatter Topics associated with a particular member's Group

Hi all,

I have a requirement where I need to develop a visualforce page in which I should display list of chatter Topics associated with a particular member's Group. I mean the group member is a User and that user's topics need to be displayed in the page when he is logged in as current user.

Below is my VF page and class:

VF page:
 
<apex:page controller="TopicController" sidebar="false">

<script> 
       (function(){try{var a=navigator.userAgent;if((a.indexOf('Salesforce')!=-1)&&(a.indexOf('iPhone')!=-1||a.indexOf('iPad')!=-1)&&(a.indexOf('OS/8')!=-1||a.indexOf('OS 8')!=-1||a.indexOf('OS/9')!=-1||a.indexOf('OS 9')!=-1)&&(a.indexOf('Safari')==-1)){ 
        var s=document.createElement('style'); 
        if(a.indexOf('OS/8')!=-1||a.indexOf('OS 8')!=-1) {
            s.innerHTML="html,html body{overflow: auto;-webkit-overflow-scrolling:touch;}body{position:absolute;left:0;right:0;top:0;bottom:0;}";
        }
        else if(a.indexOf('OS/9')!=-1||a.indexOf('OS 9')!=-1) {
            s.innerHTML="html,html body{overflow: auto;-webkit-overflow-scrolling:auto;}body{position:absolute;left:0;right:0;top:0;bottom:0;}";
        }
        document.getElementsByTagName('head')[0].appendChild(s);}}catch(e){}})(); 
    
    </script>

<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<apex:stylesheet value="{!URLFOR($Resource.OneStarter,'icons.css')}"/>
<!-- <apex:stylesheet value="{!URLFOR($Resource.OneStarter,'styles.css')}"/> -->
<apex:stylesheet value="{!URLFOR($Resource.OneStarter,'OneStarter.css')}"/>

<!-- JavaScript files -->
<apex:includeScript value="{!URLFOR($Resource.jquery)}"/>
<apex:includeScript value="{!URLFOR($Resource.TouchSwipe,'jquery.touchSwipe.min.js')}"/>
<apex:includeScript value="{!URLFOR($Resource.OneStarter,'jquery.onestarter.js')}"/>
<apex:includeScript value="/canvas/sdk/js/publisher.js"/>

    <style>
        #row1data,.colHeadr
        {
            text-align:left;
            padding:5px;
            
        }
        #bullet{padding:5px;}
        #row2data{margin-left:5px;}
        #pageblock{width:100%;}   
    }
    
    @media screen and (min-width : 480px){
        .apexp{
            margin-left: -9%;
            margin-right: -7%;
        }
    }
        
    </style>
  
 <script>
 
 function redirect(id){ 
     var id=document.getElementById(id) ;
    if( (typeof sforce != 'undefined') && sforce && (!!sforce.one) ) {
                            sforce.one.navigateToSObject(id.value);
                        }
                    else {
                            
                            window.location.href = '/'+id.value;
                    }
            }
  
 </script>
 
 <apex:pageBlock id="pb1" mode="maindetail" title="Topics">
        
        <div id="div1" style="width=100; background-color:white; ">
            <apex:pageBlockTable value="{!Topics}" var="t" 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="{!t.Name}" value="{!t.Id}"></input>
                <div id="row1data" onclick="redirect('{!t.Name}');" style="color:#16325C;font-weight: bold;">{!t.Name}</div>
                <div id="row2data" style="color:#16325C;"></div>
                </apex:column>
            </apex:pageBlockTable>
            </div>
            
        </apex:pageBlock>
 
</apex:page>

Class Code:
 
public class TopicController{
    public List<Topic> getTopics() {
        return [SELECT Name, Id FROM Topic];
    }
}

It is displaying all the chatter topics. But I need to display current user's (Group member's) Topic in page.

Any help is appreciable. Thanks in advance
Sunil MadanaSunil Madana
Hi, not sure if your problem is fixed.

Apex-Class:
public class Class_906F0000000D95jIAC {
    
    public Class_906F0000000D95jIAC(){
        CurrUserId = UserInfo.getUserId();
        cpcMap = new Map< Id, String >();
        system.debug('***DEBUG - Current User***'+ CurrUserId );        
        
        ChattergroupMemb = [ SELECT CollaborationGroupId, CreatedById, Id, MemberId FROM CollaborationGroupMember ];
        for(CollaborationGroupMember chgrpMem : ChattergroupMemb){
            system.debug('***DEBUG - CollaborationGroupMember Id***'+ chgrpMem.Id );
            if( chgrpMem.CreatedById == CurrUserId && chgrpMem.MemberId == CurrUserId ){
                system.debug('***DEBUG - CollaborationGroupId***'+ chgrpMem.CollaborationGroupId );
                Chattergroup = [ SELECT Id, Name FROM CollaborationGroup WHERE Id=: chgrpMem.CollaborationGroupId ];
                for(CollaborationGroup chtgrp : Chattergroup){
                    system.debug('***DEBUG - CollaborationGroup Name***'+ chtgrp.Name );
                    ChattergrpFeed = [ SELECT Id FROM CollaborationGroupFeed WHERE ParentId=: chtgrp.Id ];
                    for(CollaborationGroupFeed chgrpfeed : ChattergrpFeed){
                        system.debug('***DEBUG - CollaborationGroupFeed Id***'+ chgrpfeed.Id );
                        cpcMap.put(chgrpfeed.Id, chtgrp.Name);
                    }
                }
            }
        }
        
        system.debug('***DEBUG - cpcMap***'+ cpcMap );
        tpcMap = new Map< String, String >();
        for (Id key : cpcMap.keySet()) {
            system.debug('***DEBUG - cpcMap Key***'+ key );
            TopicAssignId = [ SELECT TopicId FROM TopicAssignment WHERE EntityId=: key ];
            for(TopicAssignment tpcassgnId : TopicAssignId){
                system.debug('***DEBUG - Topic Id***'+ tpcassgnId.TopicId );
                Topics = [ SELECT Name FROM Topic WHERE Id =: tpcassgnId.TopicId ];
                for(Topic tpcname : Topics){
                    tpcMap.put(tpcname.name, cpcMap.get(key));
                }
            }
        }
        system.debug('***DEBUG - tpcMap***'+ tpcMap );
    }
    
    public String CurrUserId {get;set;}
    public Map< Id, String > cpcMap {get;set;}
    public Map< String, String > tpcMap {get;set;}
    public List<CollaborationGroupMember> ChattergroupMemb {get;set;}
    public List<CollaborationGroup> Chattergroup {get;set;}
    public List<CollaborationGroupFeed> ChattergrpFeed {get;set;}
    public List<TopicAssignment> TopicAssignId {get;set;}
	public List<Topic> Topics {get;set;}
}

VF-Page:
<apex:page controller="TopicController" sidebar="false">

<script> 
       (function(){try{var a=navigator.userAgent;if((a.indexOf('Salesforce')!=-1)&&(a.indexOf('iPhone')!=-1||a.indexOf('iPad')!=-1)&&(a.indexOf('OS/8')!=-1||a.indexOf('OS 8')!=-1||a.indexOf('OS/9')!=-1||a.indexOf('OS 9')!=-1)&&(a.indexOf('Safari')==-1)){ 
        var s=document.createElement('style'); 
        if(a.indexOf('OS/8')!=-1||a.indexOf('OS 8')!=-1) {
            s.innerHTML="html,html body{overflow: auto;-webkit-overflow-scrolling:touch;}body{position:absolute;left:0;right:0;top:0;bottom:0;}";
        }
        else if(a.indexOf('OS/9')!=-1||a.indexOf('OS 9')!=-1) {
            s.innerHTML="html,html body{overflow: auto;-webkit-overflow-scrolling:auto;}body{position:absolute;left:0;right:0;top:0;bottom:0;}";
        }
        document.getElementsByTagName('head')[0].appendChild(s);}}catch(e){}})(); 
    
    </script>

<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<apex:stylesheet value="{!URLFOR($Resource.OneStarter,'icons.css')}"/>
<!-- <apex:stylesheet value="{!URLFOR($Resource.OneStarter,'styles.css')}"/> -->
<apex:stylesheet value="{!URLFOR($Resource.OneStarter,'OneStarter.css')}"/>

<!-- JavaScript files -->
<apex:includeScript value="{!URLFOR($Resource.jquery)}"/>
<apex:includeScript value="{!URLFOR($Resource.TouchSwipe,'jquery.touchSwipe.min.js')}"/>
<apex:includeScript value="{!URLFOR($Resource.OneStarter,'jquery.onestarter.js')}"/>
<apex:includeScript value="/canvas/sdk/js/publisher.js"/>

    <style>
        #row1data,.colHeadr { text-align:left; padding:5px; }
        #bullet{padding:5px;}
        #row2data{margin-left:5px;}
        #pageblock{width:100%;}
    
		@media screen and (min-width : 480px) { .apexp{ margin-left: -9%; margin-right: -7%; } }
        
    </style>
  
	<script>

	function redirect(id){ 
			if( (typeof sforce != 'undefined') && sforce && (!!sforce.one) ) {
				sforce.one.navigateToSObject(id);
			} else {                  
				window.location.href = '/'+id;
			}
	}

	</script>
 
	<apex:pageBlock id="pb1" mode="maindetail" title="Topics">

		<div id="div1" style="width=100; background-color:white; ">			
			<apex:pageBlock id="pb1" mode="maindetail" title="Topics">
				<apex:pageBlockTable value="{!tpcMap}" var="t" 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="Chatter Group Name" style="vertical-align:top;">
						<div id="row1data" style="color:#16325C;font-weight: bold;">{!tpcMap[t]}</div>
					</apex:column>
					<apex:column headerValue="Topic Name" style="vertical-align:top;">
						<div id="row2data" style="color:#16325C;font-weight: bold;">{!t}</div>
					</apex:column>
				</apex:pageBlockTable>
			</apex:pageBlock>

		</div>
		
	</apex:pageBlock>
 
</apex:page>

Hope it helps. Thanks.
Swetha A 5Swetha A 5
Hi SF-Issue Fixer,

Thank you so much for your reply and  I tried the code . It is working. I have another doubt. WIill it display all group names related to a topic. I mean if a topic named as: Test topic is there and it has 2 groups associated to it. Can It display those 2 gropus in the chatter topic.