Wednesday, March 23, 2011

Salesforce.com and validation rules

Salesforce.com supports validation rules that are evaluated when DML is performed on a record. These rules can be defined using formulae (which means you can get far more sophisticated than "required field") and the error messages can be presented in user-friendly language.

This is a far better experience than specifying required="true" for each apex:inputField, which can be too simplistic to meet business rules and will return field labels that may not necessarily be user-friendly (e.g. "Date Customer Last Contacted for Product Category A" is not suitable for customers completing a satisfaction survey).

Unfortunately these validation rules are not evaluated simultaneously - they are worked through one by one until there is an error or no rules are left. This means that for a page with 20 validation rules, the end user may have to fix 'n' click 20 times before they can save the page contents.

The only way I'm aware of at present to perform simultaneous evaluation AND present user-friendly error messages is to codify the validation rules in the controller class - bleagh!

Any better suggestions?

No comments: