Sunday 4 August 2013

Chatter for VF Page


 Display Chatter Feeds on a Visual force Page:-

  Vf page:- 


   <apex:page controller="test12">
   <apex:form id="main">
    <apex:pageBlock >
        <apex:pageBlockSection >
            <apex:inputTextarea value="{!comment}" style="width:500px;height:50px;"/>
            <apex:commandButton action="{!post}" value="Post" reRender="main,reff"/>
        </apex:pageBlockSection>
        <apex:pageBlockTable value="{!feditm}" var="f"> 
            <apex:column value="{!f.CreatedBy.Name}"/> &nbsp;&nbsp;&nbsp;&nbsp;
            <apex:column value="{!f.Body}" /> <br/>
        </apex:pageBlockTable>
    </apex:pageBlock>
   </apex:form> 
</apex:page>

class:-


public class test12 {

   
    public String comment { get; set; }
    public List<FeedItem> feditm{get;set;}
  
    public test12(){
        feed(); 
    }
   
    public void post() {
        
        FeedItem post = new FeedItem();
        post.ParentId = Userinfo.getUserId(); //eg. Opportunity id, custom object id..
        post.Body = comment;
        post.CreatedById = Userinfo.getUserId();
        insert post;
        feed();
    }
    public void feed(){
        feditm = [select Body,InsertedById,CreatedBy.Name from FeedItem ORDER BY CreatedDate desc];
        comment='';
    }
}



In above example displaying the chatter feeds on Visual force page for User.

No comments:

Post a Comment