You need to sign in to do that
Don't have an account?

How to add a not null validation in visual force page?
Hi,
i have created a field called "Name" and now i need to add a not null validation to that field.
if i created a custom button called "save", if i click save button before inserting data to the Name field i need to get a validation message.
can anyone help me on this?
You can use apex Messages in your controller Please let us know if this helps you
Thanks and Regards
sandhya
All Answers
HI jerun..
i have added required attribute to that field but my question is if he fails to give value how to throw an error in the visual force page.?
You can use the apex:pagemessages or apex:messages tag. These will automatically show error messages for form level validations
You can also use Javascript for form validation and to show error messages. The following VF page will show an error message when Name field is null.
Regards,
Ajay
You can use apex Messages in your controller Please let us know if this helps you
Thanks and Regards
sandhya
@Ajay - using javascript alert messages are not recommended as an industry trend. These are very troublesome when accessing from mobile browsers. Also, Salesforce does have standard components that can support this, so no need to go for a custom JS solution.
@Sandhya - Yes, in case we need to throw a custom message we can use a controller/extension and build the error string that needs to be returned. This returned string will be displayed in the apex:messages element on the visualforce page.