function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Tiffany BunnellTiffany Bunnell 

Duplication Error Trigger

Hi,
I have accounts that are being duplicated and assigned to a different person on a daily basis. Currently Salesforce has duplicated hundreds of accounts over the last 30 days and I now have about 35,000 extra accounts. I am being told that it is related to trigger "dc3AccountTrigger". I am not a developer and have no in-house developer. And I have no clue what I am supposed to do to fix the problem. Can anyone help me?
Thanks,
Tiffany
Arundhati DuttaArundhati Dutta
You have to set a unique filter on a field in the code of the trigger, i.e. if it gets the same value in that particular field throw an error and don't allow to save for example 'Account Number'. Take a look in this code:

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

   set<String> strString = new set<String>();

  for(Account acc:Trigger.new){
  
      strString.add(acc.Name);
  
  }
  
  
  List<Account> accList = [select Id, Name from Account where Name IN:strString];
  
  set<String> strStr = new set<String>();
  for(Account acc1:accList){
     
     strStr.add(acc1.Name);
  
  }
  
  
  for(Account acc:Trigger.new){
  
      strStr.contains(acc.Name);
      
      acc.addError('Duplicate');
      
      }
  
  }

Arundhati Dutta 
Mirketa Inc.