+ Start a Discussion
DesaiDesai 

>= not working in VF Page

Hi ,

On VF page , we are giving the below condition for required attribute ,
<apex:inputField value="{!cr.Contact.DOB__c}" label="Date of Birth" required="{!IF(cr.Contact.Primary_Officer_Percent__c >= 25, true, false)}"  >

but when the page is loaded we get the below error,

The value 'null' is not valid for operator '>='
Error is in expression '{!IF(cr.Contact.Primary_Officer_Percent__c >= null, true, false)}' in component <apex:inputField> in page jhcustomform


is it because cr.Contact.Primary_Officer_Percent__c is null when the page is loaded ? If yes is there any other way to do this ?

Thanks
Best Answer chosen by Desai
DesaiDesai
Tried this , required="{!IF(((cr.Contact.Primary_Officer_Percent__c != null) && (cr.Contact.Primary_Officer_Percent__c >= 25)), true, false)}" and it worked

thanks DeveloperSud

All Answers

DeveloperSudDeveloperSud
Hi ,
check the data type of the filed Primary_Officer_Percent__c.If that field is Boolean or checkbox then the above expression will not work.
DesaiDesai
Data Type is Percent(3, 0)
DeveloperSudDeveloperSud
Use this {!IF(!isBlank(cr.Contact.Primary_Officer_Percent__c) && cr.Contact.Primary_Officer_Percent__c >=0,true,false)}
DesaiDesai
Tried this , required="{!IF(((cr.Contact.Primary_Officer_Percent__c != null) && (cr.Contact.Primary_Officer_Percent__c >= 25)), true, false)}" and it worked

thanks DeveloperSud
This was selected as the best answer
DeveloperSudDeveloperSud
Cool .Please mark this as solved by choosing the above as best answer.
Akshay_DhimanAkshay_Dhiman

Hi Desai,

Please try the below code:

 required="{!IF(((cr.Contact.Primary_Officer_Percent__c >=0), true, false)}"
 
 // value depend on the type of Custom Field  " Primary_Officer_Percent__c" 
 //if number  then use Integer value >=0 
 //if String  then use !=null


if you found this answer helpful then please mark it as best answer so it can help others.   
  
  Thanks 
  Akshay