Can anyone explain me the difference when we set required as true in a tag, checking required as true, setting field as required at creation time and writing a validation rule ?


In terms of Visualforce, each setting has a slightly different effect:


Setting an input as true causes the field to be validated for input before any actions are executed, including getters and setters. It is only required on the Visualforce page that references it as required; when editing the record normally or using API, it will not be required. Use this to force input on a Visualforce page. It can be overridden by field level security where the user is not allowed to view or edit the contents of the field.

Field Required

Setting a field as required causes that field to be validated during the save process (e.g. calling ApexPages.StandardController.Save or using the Database.insert, Database.upsert, Database.update, update, insert, or upsert DML operations). Use this to always require a value no matter how a record is updated (e.g. API, UI, imports). This feature forces the field to appear on all layouts, and any Visualforce pages that do not present this field will not be able to successfully save if a value is not provided either by the controller or because the value was previously set. It cannot be overridden by a Visualforce page by setting the required attribute of an element to false.

Validation Rule

Setting a validation rule causes that field to be validated during the save process, as above. The difference between this and the prior entry is that the validation occurs at a different phase of the save process, and can be conditional via the formula. Use this to conditionally require a value no matter how the record is updated. If the validation rule evaluates to true, the user will be unable to save the record, even if that field is not included on the Visualforce page. Like the prior method, it cannot be overridden by setting the required attribute on the Visualforce page to false.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.