Is there a way to re-use the validation rules applied to some fields in Salesforce to a Visualforce page automaticaly?
I have a CustomController right now supporting the saving process of a field, but some required fields in the default object are not required in the Visualforce (unless I set them manually).
Thanks.
Attribution to: jpmonette
Possible Suggestion/Solution #1
Validation rules always run if they are active. If a field is defined as required then it will be required on all Page Layouts and enforced at the system level as well. Fields marked required on a Layout-by-Layout basis will need to be marked required on your Visualforce pages as well.
Attribution to: Mike Chale
Possible Suggestion/Solution #2
Validation Rules only execute when a database commit occurs (update/ insert/ upsert)
You cannot explicitly reference Validation Rules in Visualforce.
However you can logic you've already written in Validation Rules by including the apex:pageMessages tag in your VisualForce page, and letting the validation rules kick in on save - if any failures occur, they will be displayed on the VisualForce page.
Attribution to: techtrekker
Possible Suggestion/Solution #3
Well its true that validation rule fires only when you do a DML. But You can always take advantage of them in a VF page. So few changes that I will suggest use <apex:inputField>
instead of <apex:inputText>
and while saving or executing the save from a command button try to rerender the component where all the reside. All the system validation will fire and the results will be displayed beside the field or on top of the page.
Ohh and dont forget to <apex:pageMessages>
And remember when you use a <apex:inputField>
field all the FLS will be automatically applied to the field according to your/user profile.
Attribution to: Avidev9
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/4784