You need to sign in to do that
Don't have an account?
Mike Summitt
Detect duplicate emails between lead and contact.
I have the following code in the dev console, but it doesn't compile because it doesn't like my attempts to cast the aggregateresult into something I can evaluate (numerous other formats tried). Because of what it's doing, I can't use "HAVING" - if an email appears only once in lead and once in contact, I need to know that also. How can the 2 evaluation statements be changed so that they compile and execute?
Map<String, AggregateResult> LeadsByEmail = new Map<String, AggregateResult>([SELECT Email Id, Count_distinct(Id) Cnt
FROM Lead
WHERE IsConverted != true
GROUP BY Email]);
Map<String, AggregateResult> ContactsByEmail = new Map<String, AggregateResult>([SELECT Email Id, Count_distinct(Id) Cnt
FROM Contact
GROUP BY Email]);
for (AggregateResult arl : LeadsByEmail) {
if (LeadsByEmail.get(arl.Id) > (AggregateResult)'1') {
system.debug('Duplicate email - '+ arl.Id);
}
if (ContactsByEmail.containsKey(arl.Id)) {
system.debug('Duplicate email - ' + arl.Id);
}
}
for (AggregateResult arc : ContactsByEmail) {
if (ContactsByEmail.get(arc.Id) > (AggregateResult)'1') {
system.debug('Duplicate email - '+ arc.Id);
}
if (LeadsByEmail.containsKey(arc.Id)) {
system.debug('Duplicate email - ' + arc.Id);
}
}
Map<String, AggregateResult> LeadsByEmail = new Map<String, AggregateResult>([SELECT Email Id, Count_distinct(Id) Cnt
FROM Lead
WHERE IsConverted != true
GROUP BY Email]);
Map<String, AggregateResult> ContactsByEmail = new Map<String, AggregateResult>([SELECT Email Id, Count_distinct(Id) Cnt
FROM Contact
GROUP BY Email]);
for (AggregateResult arl : LeadsByEmail) {
if (LeadsByEmail.get(arl.Id) > (AggregateResult)'1') {
system.debug('Duplicate email - '+ arl.Id);
}
if (ContactsByEmail.containsKey(arl.Id)) {
system.debug('Duplicate email - ' + arl.Id);
}
}
for (AggregateResult arc : ContactsByEmail) {
if (ContactsByEmail.get(arc.Id) > (AggregateResult)'1') {
system.debug('Duplicate email - '+ arc.Id);
}
if (LeadsByEmail.containsKey(arc.Id)) {
system.debug('Duplicate email - ' + arc.Id);
}
}
try the code above. It will tell you if there are duplicates while going through the contacts
Let me knwo if it helps
All Answers
What are you trying to do in this line?
(LeadsByEmail.get(arl.Id) > (AggregateResult)'1')
try the code above. It will tell you if there are duplicates while going through the contacts
Let me knwo if it helps