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
Pankaj PariharPankaj Parihar 

dublicate records

hello friends 
can any one tell me the proper code for Merging duplicate records, i have merged files but not able to delete duplicate files.
global class batch3 implements Database.Batchable<sObject> {
    
    global Database.QueryLocator start(Database.BatchableContext BC) {
 		
        String query = 'SELECT Id,Name,Name__c,MobilePhone,Email,AnnualRevenue,LeadSource FROM Lead';
        return Database.getQueryLocator(query);
      
    }
    global void execute(Database.BatchableContext BC, List<Lead> leadlist) 
    {
        for( Lead a : leadlist)
       {
           for(Lead b: leadlist)
           { 
          		if(a.Name__c == b.Name__c )
                {
                    if(a.MobilePhone== null)
                    {
                        a.MobilePhone=b.MobilePhone;
                    }
                    if(a.Email== null)
                    {
                        a.Email=b.Email;
                    }
                    if(a.AnnualRevenue== null)
                    {
                        a.AnnualRevenue=b.AnnualRevenue;
                    }
                    if(a.LeadSource== null)
                    {
                        a.LeadSource=b.LeadSource;
                    }
                    //delete  b;
                    //[select id from Lead where Name__c='b.Name__c'];
                   	/* Lead[] dlist1 = [SELECT Id, Name FROM Lead WHERE Name__c = 'b.Name__c']; 
						try 
                        {
    						delete dlist1;
						}
                    	catch (DmlException e) 
                        {
    						// Process exception here
						}
					*/
               }
             	
           }
          // update a;
       }
      /* 	system.debug('leadlist a>>>>>'+leadlist);
        system.debug('outside loop>>>>>');
        list<lead> list1=new list<lead>();
      for( Lead a : leadlist)
       {
           for(Lead b: leadlist)
           {
          		if(a.Name__c != b.Name__c )
                {
                   list1.add(a);
                }
               else
                {
                    
                }
           }
           update a;
       }
       // List<Lead> list2 = new List<Lead>(list1);
        */  update leadlist;
        
    }   
     
    global void finish(Database.BatchableContext BC) {
      
  }
}
plz correct in this.
 
Rahul KumarRahul Kumar (Salesforce Developers) 
Hi Pankaj,

May I suggest you please refer the below link to reference. hope it helps.

Please mark it as best answer if the information is informative.

Thanks
Rahul Kumar
Pankaj PariharPankaj Parihar
Hi Rahul,
Tnx these links are helpfull but i need it in batch code form