I am returning the latest Chatter post (body and CreatedDate) for a record into a VF page. This is working great when there has been on a Chatter post on the record. However, I am having a slight issue when there has not been a Chatter post on the record. In this scenario, no value appears in my VF page where the body of the Chatter post would be (that's good and expected); however, instead of also being blank, the current date/time appears in my VF page for the CreatedDate.

Snippet from the controller:

public FeedItem LatestBody{get;set;}
List<FeedItem> posts = [select Id, Body, CreatedDate from FeedItem where ParentId in :pcw order by CreatedDate DESC limit 1]; 
    LatestBody = posts[0];

Snippet from the VF page:

<apex:outputField value="{!LatestBody.CreatedDate}"/>
<apex:outputField value="{!LatestBody.Body}"/>

It appears that when LatestBody.CreatedDate is null, the platform is defaulting in the current date/time. Anyone have any ideas on how to suppress this? The desired behavior would be return null/blank. Thanks in advance for your assistance.

  • Can't you use rendered="{!IF(LatestBody.CreatedDate != NULL,true,false)}" to hide the apex:outputField? Jul 10, 2015 at 2:14

1 Answer 1


Its always better to hide the field from visualforce page if its having null or blank value.

To do so you can use rendered attribute of most of the visualforce tags.

In your case

<apex:outputField value="{!LatestBody.CreatedDate}" rendered="{!IF(LatestBody.CreatedDate != NULL,true,false)}"/>

will hide this outputfield.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .