Last active
April 22, 2020 08:27
-
-
Save jsullivanlive/1f4d3b37bad0e8903e1aa6dc49558322 to your computer and use it in GitHub Desktop.
Salesforce Duplicate Activation Error
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From: Salesforce Duplicate Management ([email protected]) <[email protected]> | |
Subject: We can't activate your Salesforce matching rule | |
Hello James Sullivan, | |
You tried to activate the matching rule Lead Email for identifying duplicate records. However, we can't activate the rule because it defines an unusually large number of records as possible duplicates. Specifically, take a closer look at these fields: | |
Edit Lead Email to include a field that contains more unique values, and then try activating the rule again. | |
Here's a simple example of a matching rule that's too broad. Let's say that you create a rule which determines whether accounts match by looking at the billing country. If you have 1,000 accounts based in the United States, this rule is going to flag all 1,000 U.S. accounts as duplicates of one another. But most of those accounts probably aren't actually duplicates. | |
Then let's say that you change your rule to add a field with relatively unique values, such as ZIP code or street address. The rule now produces more useful results, flagging fewer records as duplicates. | |
For more information, see Match Keys Used with Matching Rules in Salesforce Help. | |
Thank you, | |
Salesforce Duplicate Management | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
used mass action scheduler to run this anon apex over and over | |
### query: | |
select Email, count(Id) | |
from Lead | |
where IsConverted = false | |
and IsDeleted = false | |
and Email != '' | |
and Email != null | |
group by Email | |
having count(Id) > 1 | |
limit 1000 | |
*/ | |
void execute( List<Map<String, Object>> sourceRecordsBatch ) { | |
// run batch with size of 1 to not hit limits | |
// we have a lot of DML that kicks off during merge | |
System.assert(sourceRecordsBatch.size() == 1); | |
String email = (String)sourceRecordsBatch.get(0).get('Email'); | |
System.assert(String.isNotBlank(email)); // paranoid | |
Set<Id> leadIds = new Set<Id>(); | |
Lead[] leads = [ | |
select Id, Email | |
from Lead | |
where Email = :email | |
and IsDeleted = false | |
and IsConverted = false | |
order by CreatedDate asc | |
limit 5 | |
]; | |
System.debug(leads); | |
Lead survivorLead = leads.remove(0); | |
for (Lead l : leads) { | |
System.assert(survivorLead.Email.equalsIgnoreCase(l.Email)); // paranoid | |
Database.merge(survivorLead, new List<Lead>{l}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment