You need to sign in to do that
Don't have an account?

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.
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.
May I suggest you please refer the below link to reference.
- http://www.dummies.com/business/customers/how-to-merge-duplicate-records-in-salesforce/
- https://help.salesforce.com/articleView?id=contacts_merge.htm&type=5
hope it helps.Please mark it as best answer if the information is informative.
Thanks
Rahul Kumar
Tnx these links are helpfull but i need it in batch code form