if(adlObj.Actual_Quantity_Received__c < 0 || adlObj.Actual_Quantity_Received__c==null)
             ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Please enter the Transaction Quantity equal to or greater than zero.'));
             return null;

In this snippet Actual_Quantity_Received__c is a number field(18,0) and i am having issue that even i am leaving the field Actual_Quantity_Received__c as empty still its taking 0 and not entering if statement.

I checked its not that i have defaulted to 0.Any reasons why this is happening?

  • Noting your reply below, is this that the field is rendered as zero on the page, or is it when the visualforce page is submitted back the field takes the value of 0? Commented Oct 18, 2012 at 7:18
  • @BobBuzzard The problem was when i used input text and submitted the field value defaulted to 0 and as soon as i changed to inputField it worked .Thanks for your reply on this Commented Oct 18, 2012 at 7:22

2 Answers 2


I suspect the issue here is related to the way that HTML inputs work. When you use an inputtext bound to a number field, there is an automatic conversion of the entered string to a numeric value. An empty number field needs to be null, but there's no way to submit a null into an HTML input - if you leave it blank it will go over the wire as an empty string rather than a null string.

According to the apex developer's guide, the string to numeric conversions should give the same behaviour as Java, but that would be to throw a NumberFormatException when trying to convert an empty string to a number, so my assumption has always been that this is a defensive technique to avoid these exceptions.

  • 1
    .Perfect and thank you .Makes lot sense but i spent almost entire day figuring that just i filled inputText instead of field i was not able to achieve my business functionality.cheers!!! Commented Oct 18, 2012 at 7:41

I do not recall the syntax off hand, but can you not simply alter the ..Received variable reference to be the "value()" of it and eval it against "0" at that point? Null, blank and zero would all qualify then, yes..?

  • Thanks no issue was when i use input text even null goes as O so i changed to input field and its working.Thanks again Commented Oct 17, 2012 at 20:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .