[SalesForce] Null check for Date field on VF Page

How do I check if a Date field is null?

Below is the code:

<apex:outputText label="Date:" value="{0, date,  MM/ dd/ yyyy}" style="text-align:center;" > 
    <apex:param value="{!care.Completion_Date__c}"/>  
</apex:outputText>

If value is null I want to show the message 'Value is null'
Can anyone please help?

Thanks.

Best Answer

You can easily do this. Just use the render condition and display two OutputText. Based on the date field it will display output.

 <apex:outputText label="Date:" value="{0, date,  MM/ dd/ yyyy}" style="text-align:center;" rendered="{!care.Completion_Date__c != null}"> 
    apex:param value="{!care.Completion_Date__c}"/>  </apex:outputText>
<apex:outputText label="Date:" value="Value is null" style="text-align:center;" rendered="{!care.Completion_Date__c == null}"/> 

Or you can also use VF function to check null validation

<apex:outputText label="Date:" value="{0, date,  MM/ dd/ yyyy}" style="text-align:center;" rendered="{!NOT(ISBLANK(care.Completion_Date__c))}">
    apex:param value="{!care.Completion_Date__c}"/>  </apex:outputText>
<apex:outputText label="Date:" value="Value is null" style="text-align:center;" rendered="{!ISBLANK(care.Completion_Date__c == null)}"/> 
Related Topic