Displaying a list of followers for a user

To get the list of users that you are following, use the following Visualforce code:

<apex:outputPanel id="resultPanel">
  <b>Following ({!followings.size})</b>
  <apex:dataList value="{!followings}" var="f">
    
    <apex:outputText value="{!f.parent.name}">
    </apex:outputText>
  </apex:dataList>
</apex:outputPanel>

The following is the code for the custom controller:

public List
<EntitySubscription>
  getfollowings() 
  {
  EntitySubscription[]  followingES = [select id, parentid, subscriberid, parent.name,subscriber.name from EntitySubscription where subscriberid =:uid];
  List
  <EntitySubscription>
    following = new List
    <EntitySubscription>
      ();
      String userSObjectPrefix = User.sObjectType.getDescribe().getKeyPrefix();
      for( EntitySubscription es: followingES )
      {
      if( ('' + es.parentid).substring(0,3) == userSObjectPrefix)
      following.add(es);
      }
      }
      return following;
      }

The EntitySubscription object stores information about entities such as users or records that you are following or subscribed to. In the custom controller code, we are firing a query over the EntitySubscription object to get the list of users and displaying the result by using the output panel and output text. Following are two attributes of the EntitySubscription object that we used in the preceding code:

  • Parented: People (subscriberid) subscribed to my feeds
  • Subscriberid: Subscribed to other peoples (parentid) feeds
    Displaying a list of followers for a user

In this change, when you choose the user from the dropdown, it will show the list accordingly.

..................Content has been hidden....................

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