Recipes by Category

App Distribution (2) Bundle logic, interface and services for distribution. App Logic (37) The Apex programming language, workflow and formulas for logic. Collaboration (5) The Salesforce Chatter collaboration platform. Database (29) Data persistence, reporting and analytics. Integration (33) Web Service APIs and toolkits for integration. Security (9) Platform, application and data security. Tools (4) tooling User Interface (36) Visualforce MVC and metadata-drive user interfaces. Web Sites (12) Public web sites and apps with optional user registration and login.
Beta Feedback
Cookbook Home » List a User's Followers on Chatter

List a User's Followers on Chatter

Post by Jon Mountjoy  (2010-07-28)

Status: Verified
Level: novice


You want to retrieve a list of all the users who are following you.


Listing which users are following me and those which I am following are very similar actions. In fact, they use the same underlying object, EntitySubscription. To display who is following me, you need to add the current User Id (your id, also referred so as the parent Id in this recipe) to limit the results.

Create a Visualforce component, and call it ChatterBubblePeeps:

<apex:component controller="BubblePeepsController" selfClosing="true">
<apex:attribute name="uID" type="String" required="true" description="User ID" assignto="{!uID}" />
<apex:Repeat value="{!followers}" var="f">
This will need the controller, BubblePeepsController, defined. The controller queries EntitySubscription, which is the key:
public class BubblePeepsController 	{	    
    public String uID    { get; set; }
    public Integer followerCount    { get; set; }

    public BubblePeepsController() {}

    public List<EntitySubscription> getFollowers()  {
         // All users who are following us
        List<EntitySubscription> followers = [select id, subscriberid,
               from EntitySubscription
              where parentid = :uid    //set the id of the user who you want to see all their followers
              order by];

        followerCount = followers.size();
        return followers;

Now you're ready to use the component in a page. For example:

<c:ChatterBubblePeeps uID="{!$}" />


You will also notice an additional parameter---allowDML---in the apex:component tag. Component Controllers, by default, do not allow the execution of DML statements (they will throw an Exception complaining about an external entry point). Make sure you set allowDML=true for this recipe to function correctly.


Recipe Activity - Please Log in to write a comment

This example throws the error Unknown property 'BubblePeepsController.followers' when deploying into our Sandbox.  New with APEX and hoping it is just not a bad API for Eclipse version.  Please advise.     

by brian.daul12032008  (2011-11-16)


Vote to Verify a Recipe

Verifying a recipe is a way to give feedback to others and broaden your own understanding of the capabilities on When you verify a recipe, please make sure the code runs, and the functionality solves the articulated problem as expected.

Please make sure:
  • All the necessary pieces are mentioned
  • You have tested the recipe in practice
  • Have sent any suggestions for improvements to the author

Please Log in to verify a recipe

You have voted to verify this recipe.