function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
fredregefredrege 

APEX and Visualforce integration

Hello folks.  This is probably very simple...

 

I am creating an apex page, and want to imbed chatter updates into the page.  The Apex code for the feed is as follows:

 

List<NewsFeed> myfeed = [SELECT Id, Type,                          

CreatedById, CreatedBy.FirstName, CreatedBy.LastName,                         

ParentId, Parent.Name,                          

Body, Title, LinkUrl, ContentData, ContentFileName,                             

(SELECT Id, FieldName, OldValue, NewValue                              

FROM FeedTrackedChanges ORDER BY Id DESC),                              

(SELECT Id, CommentBody, CreatedDate,                             

CreatedBy.FirstName, CreatedBy.LastName                             

FROM FeedComments ORDER BY CreatedDate LIMIT 10),                             

(SELECT CreatedBy.FirstName, CreatedBy.LastName                             

FROM FeedLikes)                         

FROM NewsFeed                         

ORDER BY CreatedDate DESC, Id DESC                         

LIMIT 20];

 

Of course, I can't place this code directly into a Visualforce <apex> tag (or can I?).  So the question is, where do I save this code, and how do I reference it in my VF page?

 

Thanks!

Best Answer chosen by Admin (Salesforce Developers) 
Cory CowgillCory Cowgill

You will need to use Visualforce and Apex Controllers / Extensions to accomplish this.

 

http://www.salesforce.com/us/developer/docs/pages/index.htm

 

Take a look at the section on Apex Custom Controllers and Extensions.

 

You will put your Query in the Apex Controller code. You will then bind a <apex:repeat> or <apex:datatable> to the List<NewsFeed> in the Controller.

All Answers

Cory CowgillCory Cowgill

You will need to use Visualforce and Apex Controllers / Extensions to accomplish this.

 

http://www.salesforce.com/us/developer/docs/pages/index.htm

 

Take a look at the section on Apex Custom Controllers and Extensions.

 

You will put your Query in the Apex Controller code. You will then bind a <apex:repeat> or <apex:datatable> to the List<NewsFeed> in the Controller.

This was selected as the best answer
Shashikant SharmaShashikant Sharma

Use any chatter component as per your need.

 

See this

http://blog.sforce.com/sforce/2010/08/visualforce-components-for-salesforce-chatter-here-in-winter-11.html

 

You can get examples in Visualforce Developers guide.

 

 

 

 

fredregefredrege

Cory, i created the following class in my sandbox instance of Salesforce:

 

public class News {

    public List<NewsFeed> myfeed;

    public News() {
        List<NewsFeed> myfeed = [SELECT Id, Type, 
                         CreatedById, CreatedBy.FirstName, CreatedBy.LastName,
                         ParentId, Parent.Name, 
                         Body, Title, LinkUrl, ContentData, ContentFileName,
                             (SELECT Id, FieldName, OldValue, NewValue 
                              FROM FeedTrackedChanges ORDER BY Id DESC), 
                             (SELECT Id, CommentBody, CreatedDate,
                              CreatedBy.FirstName, CreatedBy.LastName
                              FROM FeedComments ORDER BY CreatedDate LIMIT 10),
                             (SELECT CreatedBy.FirstName, CreatedBy.LastName
                              FROM FeedLikes)
                         FROM NewsFeed
                         ORDER BY CreatedDate DESC, Id DESC
                         LIMIT 20];     
    }

}

 

When I use <apex:repeat value="{!myfeed}">, I get an error that News.myfeed is an unknown property. Please help. Thanks.

Cory CowgillCory Cowgill

Visualforce needs to have get and set for the property to be visible. This is similar to JSF if you know that.

 

public List<NewsFeed> myfeed {get;set;}


fredregefredrege

Sharma, none of the available chatter components provide the updates feed as needed.  chatter:feed gives only items in a users feed, and does not iclude items he/she is following.  Thanks nonetheless.

fredregefredrege

Thanks, Cory.  Okay.  No errors, but I can't seem to get any data out.  Do you know the syntax for dumping the contents of my array?

 

Thanks again.

Cory CowgillCory Cowgill

<apex:repeat value="{!myFeed}" var="currFeedItem">

      <apex:outputText value="Body: {!currFeedItem.Body}"/><br/>

      <apex:outputText value="ID: {!currFeedItem.Id}"/><br/>

</apex:repeat>

Ankur KumarAnkur Kumar

Hi Cory, i was also facing the same issues as Fredrege. I followed the steps told by you still i am getting an error. The error message is "CustomChatterController Compile Error: sObject type 'NewsFeed' is not supported".

 

 

Here is the code of my controller :

public class CustomChatterController {
    public List<NewsFeed> myfeed {get;set;}
    public CustomChatterController (){
    List<NewsFeed> myfeed = [SELECT Id, Type,  
                          CreatedById, CreatedBy.FirstName, CreatedBy.LastName, 
                          ParentId, Parent.Name,  
                          Body, Title, LinkUrl, ContentData, ContentFileName, 
                              (SELECT Id, FieldName, OldValue, NewValue  
                               FROM FeedTrackedChanges ORDER BY Id DESC),  
                              (SELECT Id, CommentBody, CreatedDate, 
                               CreatedBy.FirstName, CreatedBy.LastName 
                               FROM FeedComments ORDER BY CreatedDate LIMIT 10), 
                              (SELECT CreatedBy.FirstName, CreatedBy.LastName 
                               FROM FeedLikes) 
                          FROM NewsFeed
                         ORDER BY CreatedDate DESC, Id DESC 
                         LIMIT 20];
     }  
}

 

Please Help.. Thanks.

Cory CowgillCory Cowgill
Update your metadata version to 27 on the apex and Visualforce.