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];
if(!posts.isEmpty()){
LatestBody = posts[0];
}
Snippet from the VF page:
<td>
<apex:outputField value="{!LatestBody.CreatedDate}"/>
<br/>
<h4>
<apex:outputField value="{!LatestBody.Body}"/>
</h4>
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.