You need to sign in to do that
Don't have an account?
anu.s1.3587621171560732E12
How to delete lead duplicate records using do while loop
Hi,
I just uploaded 3000 more lead records in my salesforce instance. After insersion I find out the duplicate lead records with same phone number.now i want to delete the duplicate records based on phone number and also Industry criteria.
is it possible to do using do while loop in the trigger.if it is possible means please send me an example code.
we can do by do while but i prefer for loop over here
List<String> myphoneList = new List<String>();
for(Lead l: [ SELECT Name,Phone FROM Lead]){
myphoneList.add(l.Phone);
}
List<Lead> mydups = new List<Lead>();
for(Lead l:[SELECT Name,Phone FROM Lead WHERE Phone IN :myphoneList]){
//add duplicate into one list
mydups.add(l);
}
//delete
delete mydups;
All Answers
Istead of using do while loop you can easy to get duplicate records of loop by using
List.contains() method.
Actuallly my problem is
suppose if one record dont have criteria the other one can have criteria,but phone numbers are same for both the records.
so I want to merge the criteria and I want to delete remaining records.
It could be thankful if you send any example code regading this issue.
we can do by do while but i prefer for loop over here
List<String> myphoneList = new List<String>();
for(Lead l: [ SELECT Name,Phone FROM Lead]){
myphoneList.add(l.Phone);
}
List<Lead> mydups = new List<Lead>();
for(Lead l:[SELECT Name,Phone FROM Lead WHERE Phone IN :myphoneList]){
//add duplicate into one list
mydups.add(l);
}
//delete
delete mydups;
@ Rakesh
We dont have contains method for list in salesforce
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_list.htm
Thank you so much for the code.