Authored by Zishan Razzaq

Tuesday, December 23, 2008

How to Create a Validation Rule in Salesforce.com(Force.com)

What Are Validation Rules in Salesforce.com:
From Salesforce.com Premier Support Rep:
"Validation rules verify that the data a user enters in a record meets the standards you specify before the user can save the record. A validation rule can contain a formula or expression that evaluates the data in one or more fields and returns a value of "True" or "False." Validation rules also include an error message to display to the user when the rule returns a value of "True" due to an invalid value."

In simplest terms, some rule that you would like to do checks on your system, record.

So, Validation Rules are Available in: Group, Professional, Enterprise, Unlimited, and Developer Editions.

To create validation rules:
  • Go to the Object you would like to create the validation rule on. To get to that object click Setup and then Customize. If it is a standard object like Account, Contact, Opportunity, Product, etc.
  • If it is a Customize Object then click on Setup==> Create==>Objects and then click on the object you like.
  • Now click on Validation Rule and click New.
  • Give your Validation a Name
  • Give it a Description (not needed but helps in the long run and good practice)
  • Check the Active Box to make it Active
  • Error Condition Formula: This is where you place in your expression to validate the field. For example: Let say you want to validate that US States Field to have 2 abbreviations in it. The rule would be something like:
  • AND (
    OR(BillingCountry = "US", BillingCountry="USA", LEN(BillingCountry)=0),
    OR(
    LEN(BillingState) < 2, NOT( CONTAINS("AL:AK:AZ:AR:CA:CO:CT:DE:DC:FL:GA:HI:ID:" & "IL:IN:IA:KS:KY:LA:ME:MD:MA:MI:MN:MS:MO:MT:NE:NV:NH:" & "NJ:NM:NY:NC:ND:OH:OK:OR:PA:RI:SC:SD:TN:TX:UT:VT:VA:" & "WA:WV:WI:WY:PR:MP", BillingState) )))
  • Now in the Error Message Place in the Error you would like the User to see or get.
  • Like : A valid two-letter state code is required.
  • Error Location: Do you want to display the error on top of the page or next to the field itself. If you want it next to the field then click field and choose your field from the picklist.
  • Click Save to finish or Save & New to create additional validation rules.
Done...
Thanks
View my Other Blogs:
VisualForce Made Easy
Salesforce Data Migration Made Easy

3 comments:

  1. Hello I am very new to Apex and i am trying to write a validation rule that alerts the owner when anoppurtunity is set to closed won...Here is what i have so far. Any suggestions? I would really appreciate the help. Thanks



    IF(
    AND (
    ISPICKVAL( StageName, "Closed Won"),

    )

    ReplyDelete
  2. i think you must do this with help of Workflows as this is a automation process not a validation.

    write on update of a record event

    rule criteria: ISPICKVAL(StageName, "Closed Won")

    then send an email through action

    ReplyDelete
  3. HI i was very happy to see this blog...
    Plz i request anyone over here to help me..
    Iam being a fresher to salesforce.com i had a few queries regarding salesforce jobs. I want to start my career in salesfoece so i choose to be an admin or CRM. I feel little discomfort in coding.. i prefer nondevloper roles in salesforce so guys plz help me in picking a right path for me.. plz suggest me ... I want to know the work, roles and responsibility of a salesforce admin or crm professional. plz reply me.. plz plzzz plzz i say plzzzz iam struggling to find the answers for it because i dont have any support...to guide me

    ReplyDelete