Using Chatter in Apex

Although Chatter data is accessible in Apex using SOQL queries, Chatter in Apex provides a simpler solution. It consists of a series of Apex classes called ConnectApi that expose Chatter features in a simpler way, as an API rather than a data model. With Chatter in Apex, Chatter data is preformatted for display, and many features can be accessed with a single method call. Using the data model is typically not as easy or concise.


Note

For more information about Chatter in Apex, visit the online documentation at http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_connect_api.htm.


Listing 12.13 and Listing 12.14 are the Visualforce controller and page to display the current user’s feed items and comments. The Chatter in Apex getFeedItemsFromFeed method returns the posts and comments for the current user (the 'me' argument), and these are iterated over in the Visualforce page using nested repeat components.

Listing 12.13 Visualforce Controller for Chatter Example


public with sharing class MyPageController12_13 {
  public List<ConnectApi.FeedItem> getFeedItems() {
    return ConnectApi.ChatterFeeds.getFeedItemsFromFeed(null,
      ConnectApi.FeedType.Record, 'me').items;
  }
}


Listing 12.14 Visualforce Page for Chatter Example


<apex:page controller="MyPageController12_14">
<style>
img { margin: 4px; width: 25px; }
.actor { font-weight: bold; }
.comments { margin-left: 40px; }
</style>
<apex:repeat value="{!feedItems}" var="feedItem">
<div>
  <apex:image url="{!feedItem.photoUrl}"/>
  <span class="actor">{!feedItem.actor.name}</span>:
  <span class="text">{!feedItem.body.text}</span>
  <apex:outputPanel >
    <apex:repeat value="{!feedItem.comments.comments}"
     var="comment">
      <div class="comments">
        <apex:image url="{!comment.user.photo.smallPhotoUrl}"/>
        <span class="actor">{!comment.user.name}</span>:
        <span class="text">{!comment.body.text}</span>
      </div>
    </apex:repeat>
  </apex:outputPanel>
</div>
</apex:repeat>
</apex:page>


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

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