+ Start a Discussion

Check for Duplicates

    I am new to Salesforce development. I have not learned APEX yet, but am planning on learning it.

I have a situation where duplicate accounts are multplying like crazy.

1) I found a solution online where you can override the 'new' account button to force users to search for an account before entering a new one. This would help, but the code is not working. When I hit 'Check' or 'New' it locks up and then kicks me out of salesforce and makes me log in again. This happens over and over

Here is the website where I got the code: http://wiki.apexdevnet.com/index.php/Avoid_Create_duplicated_Account_Name

2) If #1 above could work, this would at least help me.
3) Another issue we have is that a  company could be called ABC Co, ABC inc, or Alpha Beta Delta inc. Obvisouly if the account in salesforce was listed as Alpha Beta Delta inc, then if someone searched for ABC inc.,it would not show up since the account was under the long name and not the short name.

Therefore, I developed something off-line in Excel that reads a report from Salesforce and the user enters the E-mail Domain of the company they are searching for. If the e-mail domain exists for more than one company AND the company does not have a parent, the VBA code spits out an error report.If the e-mail domian exists and only exists for one company then it tells them the account ID and account owner for that account and the user can search under Account ID in salesforce rather than account name

So... Basically #1 would get me way further than we are today. I am having trouble forcing people to search for accounts, which means that # 3 is pretty useless since they are not searching for accounts anyway.

The pie in the sky solution would be to have #1, combined with #3.

Any advice would be greatly appreciated, the duplicates probably doubled just in the time I wrote this message!

trigger accountDulicatePreventer on Account (before insert, before update) {

Map<String,Account> accountMap=new Map<String,Account>();

for( Account account : System.Trigger.new){

if((account.Name!=null)&&(System.Trigger.isInsert ||

(account.Name != System.Trigger.oldMap.get(account.Id).Name))){


account.Name.addError('Another new account has the same account name.');






for(Account account : [SELECT Name from Account WHERE Name IN : accountMap.KeySet()]){

Account newAccount = accountMap.get(account.Name);

newAccount.Name.addError('An Account with this Account Name is already exists.');




Here is code to prevent duplicate account name.

    So is this an S-Control or a Trigger? Where do I put the code? Also, does this prevent or warn someone if they search for ABC and the account is actually ABC co.?

Sorry, I'm VERY new.;


this is trigger.

I guess it does not recognise with abd and abc co.Both will be different.

But if you have same format every time you can change code.
We don't always have the same format.
1) I want to force them to search rather then them just adding a new account, so when they hit the 'New' Button it forces a search rather than taking them to the Account Object.

2)  I would like to somehow check if a contact in the system's e-mail domain = Company ABC and then they try to enter another contact with the same e-mail domain and try to add account Compan ABC co... I want the system to realize that the e-mail domain is already linked to Company ABC