Monday, November 19, 2012

Data validation rules in Force.com

We all make mistakes when entering data and we expect the application to catch all those errors. For example a 'Quantity' field in an order submission form. Does it make sense if user enters a zero value or a -ve value for it? Applications need to have a way of verifying if the data entered is sensible. Force.com platform provides a built-in feature, an easy way to catch all those errors by letting the developers define validation rules for the fields.

Let us learn the steps involved in putting together a validation rule. 


Step 1 - Decide the object and the field for which you will be adding a validation rule. For your object of choice go to its object definition detail page via App Setup -> Create -> Objects and then clicking on the link for your object label.


Step 2 - There you will  see a link (towards the top) called 'Validation Rules'. Or just few sections below, you will see a section called 'Validation Rules' with a button 'New'. Either click on this 'New' button or hover over the top link and click on the 'New' button there.

Step 3 - You will be taken to a page where you are allowed to enter Rule Name, Description, Error Condition Formula and Error Message to display. Error Condition Formula section is where we spend our time coming up with the validation rule. But wait a minute! Have you read my previous article Custom Formula Fields in Force.com? If you have read it and have spent enough time to come up with 'Custom Formula' Fields, this section should look very familiar. Go ahead, play with this section and put together your validation rule.

Step 4 - Enter the Error Message you want to display when the 'Error Condition Formula' you have setup is true and the location for the message to be displayed.

Go ahead and save your validation rule. That was quick and easy isn't it?

Happy cloud computing using Salesforce!

1 comment:

  1. Thanks for providing great information and Nice Blog, this blog is very informative
    Address Standardization Software

    ReplyDelete