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
maddukurimaddukuri 

Need to display a String for a currency field if it has no value in it - VF page

I have a VF page that has the following line,

<td align="center"><apex:outputField value="{!pc.Waste1_Ctr_Box1_Fee__c}"/></td>

 

pc.Waste1_Ctr_Box1_Fee__c is a currency field in an object that is set in the controller. My requirement is to diplay "N/A" if there is no value in that field. Can I do that?

 

I tried to change outputField to OutputText and put a property variable say "nastr" of type String and set it to 'N/A' if there is no value in the field. for example,

<td align="center"><apex:outputText value="{!IF(NOT(ISNULL(pc.Waste1_Ctr_Box2_Fee__c)),pc.Waste1_Ctr_Box2_Fee__c,nastr)}"/></td> but it gives me an error. Does the property variable need to be only decimal since the field is a currency field? If I change it to Decimal and set it to 0, it works but the $ sign is missing and there is only one place after the decimal.

 

Is there any way that the currency field can display "N/A" when there is no value in it. Any input is greatly appreciated.

 

Thank You!

Best Answer chosen by Admin (Salesforce Developers) 
maddukurimaddukuri

Thank You very much!

With your suggestion, this is what I had and it works.

<tdalign="center">

<apex:outputTextrendered="{!ISNULL(pc.Waste1_Ctr_Box1_Fee__c)}"value="N/A"/>

<apex:outputTextrendered="{!NOT(ISNULL(pc.Waste1_Ctr_Box1_Fee__c))}"value="{0,number,$#,###,###.00}">

<apex:paramvalue="{!pc.Waste1_Ctr_Box1_Fee__c}"/>

</apex:outputText></td>

 

Thank You once again!

 

All Answers

vishal@forcevishal@force

Yes, since it is a decimal field, you cannot give it a value of "NA".

 

What you can do is, take <apex:outputField> along with an <apex:outputText> , use the outputText to display NA, when there is no value in the field.

 

You can handle their visibilities using rendered.

 

Something like:

 

<td align="center">

      <apex:outputField value="{!pc.Waste1_Ctr_Box1_Fee__c}" rendered="{!pc.Waste1_Ctr_Box1_Fee__c != NULL}"/>

      <apex:outputText value="NA" rendered="{!pc.Waste1_ctr_Box1_Fee__c == NULL}"/>

</td>

maddukurimaddukuri

Thank You very much!

With your suggestion, this is what I had and it works.

<tdalign="center">

<apex:outputTextrendered="{!ISNULL(pc.Waste1_Ctr_Box1_Fee__c)}"value="N/A"/>

<apex:outputTextrendered="{!NOT(ISNULL(pc.Waste1_Ctr_Box1_Fee__c))}"value="{0,number,$#,###,###.00}">

<apex:paramvalue="{!pc.Waste1_Ctr_Box1_Fee__c}"/>

</apex:outputText></td>

 

Thank You once again!

 

This was selected as the best answer