+ Start a Discussion

How do I make my account name unique?

According to help if i want to make my account name unique i need to make sure my syntax is "name" in validation rules. But it doesnt seems to work as validation rules will only return true/false. Did I make any mistake? Please help me.
Best Answer chosen by Admin (Salesforce Developers) 


I tested EricB solutions and it works...

Thanks alot

All Answers

I think the syntax of the validation rule in that article may be wrong.  It seems to me it should be more like:


(or whatever it is you named your unique name field)

This would return true if the name were different than your field, which would generate an error, which is what you want.

You could also do this with an Apex trigger if you'd like.

hi werewolf,

If i want to make my standard Account Name unique, how should I do it? Since we cant change standard field into unique.

Can you teach me the easiest way to do it? I have no idea on how to create a apex trigger.

Thanks & Regards


The article specified tells you how to make the standard account name unique.  The wrinkle is that you have to actually make a copy of the name and put it in another field -- and that _other_ field is unique.
If you'd like to learn about Apex triggers, have a look at the Force.com Cookbook:
Dear Hardhat,
Thanks for your reply and the link provided. I guess i will give a try on the trigger
The solution shown in the original post is incorrect.  I have notified the author of the solution to update it.

You should use a workflow field update formula instead of a validation rule to copy the value of "Account Name" into "Account Name Copy" every time a record is created or updated. 
I would also recommend that you turn off the Required attribute of the custom field and do not display it on page layouts.  There's no reason for your users to see this field.

The last step is that you need to populate the Account Name Copy field for all of your existing account records.  You can do this via the Excel Connector or Data Loader. 

Hope this helps,


But wait -- that doesn't sound right.  The workflow field update will only run if it validates correctly.  Let's say you have an existing account called "Smith," and so Unique_Account__c for that account also contains "Smith."

Now you make a new account and also set its name to Smith.  It will save just fine, but when the workflow field update runs, it will violate the uniqueness constraint, which will negate that workflow field update, and it won't commit.  Therefore you'll have one account where Name="Smith" and Unique_Account__c="Smith" and another account where Name="Smith" and Unique_Account__c="".  So you still have a duplicate account name, no?

If the workflow field update fails due to the unique constraint violation, the entire save is aborted. It effectively works like a type of validation.  (Note that workflow runs AFTER validation rules and Apex triggers.)

Give it a try.  The unique constraint error appears at the top of the page with a hyperlink to the other record with the same name.


I tested EricB solutions and it works...

Thanks alot

This was selected as the best answer
Tushar Arora 20Tushar Arora 20
You can always use a validation rule with Vlookup to make your name field as unique. Simply make a validation rule in Account with the following error formula to display error message if we try to insert a record with a Name that already exists.
AND(VLOOKUP($ObjectType.Account.Fields.Name,  $ObjectType.Account.Fields.Name , Name)  =  Name ,    OR(ISNEW(),ISCHANGED(Name))  )
@Tushar, i don't think this validation rule is working. 
Error: Field $ObjectType.Account.Fields.Name does not exist. 
Hemendra Malik 12Hemendra Malik 12
Create a duplicate rule for Account name with the exact match. This will not allow the user to enter an account with existing account name.