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
ralphralph 

How to replace null or empty number value with 0 - in VF

How to replace null or empty value with 0.

I am passing 12 number fields to a Google chart.
If one of my fields is blank the chart does not render.
In my Visualforce page I what to replace the null value with 0.
Both of the following lines of code always return false even though one is ==null and the other is !=null.
['January',  {!if(Contact.Sales_01__c==null, 0, Contact.Sales_01__c}],
['January',  {!if(Contact.Sales_01__c!=null, 0, Contact.Sales_01__c}],

How do I do this in Visualforce without using a controller extension?
Another question: can I use a static Apex method and pass in the value and get back 0 if null, or the passed value not null?

Thanks.

Best Answer chosen by Admin (Salesforce Developers) 
Alok_NagarroAlok_Nagarro

Hi,

 

you can do that with visualforce page in the following way -

 

['January',  {!IF(OR(ISNULL(Contact.Sales_01__c),ISBLANK(Contact.Sales_01__c)), 0, Contact.Sales_01__c}],

Hope it would help !

All Answers

Alok_NagarroAlok_Nagarro

Hi,

 

you can do that with visualforce page in the following way -

 

['January',  {!IF(OR(ISNULL(Contact.Sales_01__c),ISBLANK(Contact.Sales_01__c)), 0, Contact.Sales_01__c}],

Hope it would help !

This was selected as the best answer
ralphralph

Thanks Alok - this worked! Amazing.

Where should I have looked to find this?

I searched the Visualforce documentation and isNull has one hit but isEmpty found 0.

The Apex documentation has isEmpty for collections.

Thanks again.

ralphralph

My bad - I should have been looking for isBlank.

Found it in the Functions section of the Visualforce documentation.

 

SamuelDeRyckeSamuelDeRycke

Still, you can't always find everything in the documentation. Sometimes the solution you want is a combination of documentations,  programming practises and some nifty thinking. That's what the community is for !