There is this Visualforce page. There are several fields in that page which I want to make mandatory. So I tried, starting by one field. So if the fields are empty, I don't want the user to pass on to the next page. I tried putting

required = "true"

in visualforce page block that helped me preventing from the user going to next page but it did not show any kind of error or so through which the user can come to know what is missing.

I tried the following code for validation rule but it didn't work. Am I doing something wrong here ?

ISBLANK( Mailing_Street__c )
  • 1
    In what way did it fail to work?
    – user735
    Feb 3, 2015 at 17:28
  • please explain ur scenario
    – Vignex
    Feb 3, 2015 at 17:28

2 Answers 2


Validation Rules are displayed normally in a VF page (on field OR on the top of the page, based on rule) if you are leverage a Standard Controller. There can be two ways to save a record and both of them behave differently with Validation rules.

  1. Controller.Save() - Using this method to Save, results the same behavior when you click standard Save button. All the Validation rules will execute and the error message would be displayed according to the validation rule. You also don't need to worry about the placement of the error message because that's already handled in the Validation rule.

    Pagereference pageref; pageref = controller.save(); return pageref;

I would also not use try, catch block with this method because this catch never executes with this method. Hence, there is no point writing it.

  1. DML statements like insert - However, if you are using DML statements then it becomes imperative to use try and catch to capture the message and display on the VF page. You just need to catch the exception message and display the same using ApexPages.addMessages(e). The resulting behavior of this technique is different from standard controller save() but it will definitely display the validation rule error message.

Hope this helps.!!


I see that you are using a visualforce page. My guess is that you are using a standard object which may not follow the same pattern as a custom object. If you are writing for a contact then it should be ISBLANK(MalingStreet). Check in your object definition to get the correct API fieldname, as the ISBLANK() is the correct validation rule to be using.

  • you are right. I am using standard object Account. Let me try what u said here.
    – LazyBones
    Feb 3, 2015 at 17:44

You must log in to answer this question.

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