Displaying a Chatter follower on the Visualforce Page

To show chatter followers or to record follower details on a Visualforce page, use the <chatter:followers> tag. The <chatter:followers> tag has a few attributes:

  • entityId: It is the ID of the record for which the list of followers has to be displayed; for example, Account.Id.
  • ID: It is an identifier that allows the component to be referenced by other components in the page.
  • Rendered: It is a Boolean value that specifies whether the component is rendered on the page. If it is not specified, this value defaults to true.

The following code snippet shows the use of these attributes:

<apex:page showChat="true">
 <Chatter:followers entityId="00590000001qt4z"/>
</apex:page>

In the preceding code, entityId is the user ID (Rakesh Gupta); so, in output, it will show the followers of the mentioned user; it can be done in the same way for records.

Displaying a Chatter follower on the Visualforce Page

To make the preceding functionality dynamic, Apex code is required. Following is the sample code to control the dynamic behavior of the page.

First create a list of users in your organization. The following code shows whether users from your organization are active or inactive. According to your need, you can modify query in code. To create a dropdown of the available users in an organization, the Visualforce code to be used is as follows:

<apex:outputLabel value="Select user"></apex:outputLabel>
<apex:selectList id="user" value="{!uName}" size="1" title="User">
<apex:selectOptions value="{!users}" ></apex:selectOptions>
<apex:actionSupport event="onchange" action="{!followchange}" rerender="feed" status="loadStatus"/>
</apex:selectList>

The following is the controller code:

public List
<selectOption>
  getUsers()
  {
  List
  <selectOption>
    options = new List
    <selectOption>
      ();
      options.add(new selectOption('', 'Current User'));
      for (User users : [SELECT Id, Name FROM User ]) 
      {
      options.add(new selectOption(users.Id, users.Name));
      }
      return options;
      }
Displaying a Chatter follower on the Visualforce Page

From this page, select any username from the dropdown; it will show the followers accordingly. To control the dropdown and show the followers dynamically, refer to the following Visualforce and controller code snippet:

<apex:outputPanel id="feed">
  <chatter:followers entityId="{!uid}"/>
</apex:outputPanel>
<apex:actionStatus id="loadStatus" startText="Loading..." /> 

public PageReference followchange() 
          {
            uid=uName;
            
          }

On the Visualforce page, use the output panel to display the outcome. In the entityId attribute of the chatter:followers tag, use {!uid} to get the list of followers from the controller.

Displaying a list of followers without using the Chatter tag

To display the list of followers without using the Chatter tag, create an output panel to show the result.

The following is the Visualforce code:

<apex:outputPanel id="resultPanel">
  <b>Followers ({!followers.size})</b>
  <apex:dataList value="{!followers}" var="f">
    <apex:outputText value="{!f.Subscriber.Name}">
    </apex:outputText>
  </apex:dataList>
</apex:outputPanel>

To get the list of followers in the apex class, fire a query on the EntitySubscription object (this object contains all information about the followers).

The following is the controller code:

followers=  [select id, subscriberid, subscriber.name
      from EntitySubscription
      where parentid =:uid];
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.169.40