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
THUNDER CLOUDTHUNDER CLOUD 

How to prevent duplicate lead records to insert through data loader ?

ManojSankaranManojSankaran

Hi 

There are multiple options available for this.

1. You can set duplicate rules in salesforce for lead
2. You can create a unique field in salesforce which is a combination of the fields that you want to check for uniquness (Name+Phone+SSN) . Populate this field using workflow
3. Use trigger to restrict the duplicate.

If this solves your query mark it as answer.

Thanks
Manoj S

THUNDER CLOUDTHUNDER CLOUD
How to prevent using trigger.
ManojSankaranManojSankaran

Hi, 

Trigger should be the last option.

It should be a "before trigger" and below is the logic

Set<String> Name, PhoneNumber, SSN

get these values from Trigger.New
Query all leads based on the set (Name,PhoneNumber,SSN)
           add the leads queried into a map 
           Key should be  (Name+PhoneNumber+SSN)
      
Iterate Trigger.New
If the newly created lead has the same key
 then add trigger.adderror


Mark it as answer if it helps you.
Thanks
Manoj S

 

Vishal ThubeVishal Thube
Hi, Below is my code for the trigger for prevention duplicate Name in the account . 
1.Best Code & Small
2.Flexible
3.Bulkify
4.scalability

Try it once.... n hit like if u like it
 
trigger PreventDuplicateAccName on Account (before insert,before Update ){
    Set <string> accSet = new Set <String>();
        
    for (Account objAcc : trigger.new){
         if (accSet.contains(objAcc.Name)){
            objAcc.addError('Account Found......');
        }
        accSet.add(objAcc.Name);   
    }   
    
    List <Account> accList = new List <Account>();
        for (Account objAcc : [select id, Name from Account where Name In : accSet]){
            accList.add(objAcc);
            
            if (accSet.equals(accList)){
                objAcc.addError('Record Alreday Found ');
            }   
    	}       
}