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
Michael MMichael M 

Apex Outputfield default text

I have a simple VF page that displays one field from the object. If the field is blank/null, I want the page to display text that says "No notes entered". Is there a way to do this? 

Here is my page so far:

<apex:page standardController="Discharge__c" lightningStylesheets="true">
    <apex:pageblock >
       <apex:repeat value="{!Discharge__c}" var="dc">
                <apex:outputField value="{!dc.Progress_Notes__c}" id="aa"/> 
        </apex:repeat>
        </apex:pageblock>
</apex:page>
Best Answer chosen by Michael M
SarvaniSarvani
Hi Michael,

You can try like below:
<apex:outputField value="{!dc.Progress_Notes__c}" rendered="{!dc.Progress_Notes__c != NULL}"/>

 <apex:outputText value="No notes entered" rendered="{!dc.Progress_Notes__c== NULL}"/>

Hope this helps!

Thanks

All Answers

SarvaniSarvani
Hi Michael,

Please try this in line 4:
<apex:outputText value="{!IF((dc.Progress_Notes__c== null), 'No notes entered', dc.Progress_Notes__c) }" id="aa"/>
Hope this helps! Please mark as best if it does.

Thanks
 
Michael MMichael M
Thank you Sarvani. I tried it, and the "no notes entered" displays, however, the field is not displaying neatly. I have a trigger that organizes the data of the field a certain way, and when I use apex:outputfield it honors that trigger, however when I use apex:outputText, it just displays the text all together without honoring the line breaks that I specify in the trigger. Is there a way to do this task with apex:outputField?
SarvaniSarvani
Hi Michael,

You can try like below:
<apex:outputField value="{!dc.Progress_Notes__c}" rendered="{!dc.Progress_Notes__c != NULL}"/>

 <apex:outputText value="No notes entered" rendered="{!dc.Progress_Notes__c== NULL}"/>

Hope this helps!

Thanks
This was selected as the best answer
Michael MMichael M
Excellent, this works,  thank you.