2

I am currently working on using "Chatter in APEX" aka ConnectApi to display feeds from custom object records in a Visualforce page.

I am using one VF page with links that re-render the same page but different data which is based on a param value(category).

I need to display the latest Chatter feed that is the latest feed item from the last 10 modified records which belong to a certain category and this will also change when the page is re-rendered(different category is selected).

I managed to accomplish this but I am running into the rate limits which is about 200 requests per user per hour.

This is how I am fetching the latest feed items from the 10 most recent documents.

lastUpdatedDocs = [SELECT ........ FROM Custom_Object where ........ ORDER BY LastModifiedDate DESC LIMIT 10]

global List<FeedItemInfo> getChatterFeedForDisplay() {
        List<FeedItemInfo> result = new List<FeedItemInfo>();

        try
        {
            for (Custom object doc :lastUpdatedDocs)
            {
                ConnectApi.FeedItemPage feed = getNewsFeed(doc.Id); 
                if (feed != null) 
                { 
                            //add first item from feed to display in VF page
                    result.add(new FeedItemInfo(feed.items[0],doc));
                }
            } 
        }

        catch(Exception e)
        {

        }


        return result;
    }

global ConnectApi.FeedItemPage getNewsFeed(Id docId) {          

        try{

        //get feed for this record.
        return ConnectApi.ChatterFeeds.getFeedItemsFromFeed(null, ConnectApi.FeedType.Record, docId);
        }

        catch(Exception e)
        {

        }
        return null;

    }

So in essence, I am getting the last 10 modified documents and then making a call to the API to get the feed for each one of them and then getting the first feed item from each.

Since a user may click on the various links a few times, he will run into the limits pretty fast.

So is there a better approach to this problem and is there any way I can "cache" this information for the first time a user clicks a particular link for the given session.

Adding this to the Apex:page only seems to cache data for the initial page load(default category) and not for the other links.

cache="true" expires="900"

Secondly do the Chatter API limits count towards the overall API limits of an org or are they separate?

Thanks.

  • 1
    Chatter REST API limits are per user per connected app per hour. They are different from the general API limits. wiki.developerforce.com/page/… – techtrekker Sep 16 '13 at 23:35
  • Would it be possible to use a single call to ConnectApi.ChatterFeeds.getFeedItemsFromFilterFeed() instead? It's not exactly the same as your code, but maybe you can do some additional filtering on the ConnectApi.FeedItemPage that comes back. Docs: salesforce.com/us/developer/docs/apexcode/Content/… – alouie Sep 19 '13 at 6:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.