+ Start a Discussion
Malisa Gibbons 9Malisa Gibbons 9 

How do I write a validaton rule that will prevent a certain account name?

I need to prevent accounts from being loaded for certain customer.  How do I write a rule to prevent a certain name being used as an account name?
Martha VMartha V

Follow these instructions (https://help.salesforce.com/articleView?id=fields_defining_field_validation_rules.htm&type=5) to get to where you are going to add the validation rule

Then fill in the following

Rule Name - Give your rule a name like "Reject Account XXXX"
Active - Checked
Description - Account XXXXX can not be added
Error Condition Formula - CONTAINS(UPPER(Name), 'XXXX')
Error Message - "the company XXXX can not have an account"  - or whatever you want people to see when they enter the name of that account
Error Location - choose whether you want the error message to show by the name field or at the top of the page.

-- the problem I see with this is that if someone changes the name just a little this error will not be caught.
The formula:

  • Upper(name)  -- changes all the leters in the string to uppercase letters so when you add the name of the company you are comparing to type in all uppercase.  
  • CONTAINS(string1, string2) -- returns true if String1 contains String2. Using CONTAINS in the formula will help if someone types in the name and adds something else, but if there are other companies that could be caught in that they would not be saved either. So you would have to judge if you want to use the CONTAINS or not. If you don't want to use it then your formula would be UPPER(Name) == 'XXXX' where Name is the Account.Name and XXXX the name of the company you don't want to add.
I hope this was what you were looking for.
GovindarajGovindaraj
Hi Malisa,

In addition, we can include the action to New or edit.

AND(OR(ISNEW(),ISCHANGED(Name)),OR(CONTAINS('SOME_VALUE', UPPER(Name)),CONTAINS('SOME_VALUE', UPPER(Name))))

Include as many condition using CONTAINS and replace the SOME_VALUE with your value.

Thanks,
Govindaraj.S