I'm trying to compare Lead
and Contact
email addresses for duplicates and then list the duplicate emails on a Visualforce Page
.
I'm basically querying all Lead
records in the system (1239) and all Contact
records (3681). I then add the emails to 2 separate List<String>
, then loop through adding duplicates to a a Set<String>
for duplicates.
Dupes then gets passed through to my Visualforce Page
.
This works on a small set of data in sandbox but cant handle the larger volume.
Here's my code:
global class deDuper {
global Set<String> Dupes {
get;
set;
}
global deDuper() {
List<String> leadEmails = new List<String>();
List<Lead> Allleads = [SELECT Email FROM Lead WHERE Email != null];
List<String> ContactEmails = new List<String>();
List<Contact> AllCons = [SELECT Email FROM Contact WHERE Email != null];
for (Contact ConstoAdd : AllCons) {
ContactEmails.Add(ConstoAdd.Email);
}
for (Lead LeadstoAdd : Allleads) {
leadEmails.Add(LeadstoAdd.Email);
}
Dupes = new Set<String>();
for (String L : leadEmails) {
for (String C : ContactEmails) {
if (L == C) {
Dupes.Add(L);
} else {
}
}
}
}
global Set<String> getDupes() {
return Dupes;
}
}