Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entity Type Compare on Rule Matches + Standard Account Matching Rule #11

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/classes/INT_InteractionProcessor.cls
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ public class INT_InteractionProcessor {
Database.DuplicateError dupErrorError = (Database.DuplicateError) error;

for (Datacloud.MatchResult matchResult : dupErrorError.getDuplicateResult().getMatchResults()) {
if (matchResult.getEntityType() == 'Lead'){
for (Datacloud.MatchRecord match : matchResult.getMatchRecords()) {
// Grab matched record to use instead of the new one.
interaction.Lead__c = match.getRecord().Id;
Expand All @@ -371,6 +372,7 @@ public class INT_InteractionProcessor {
}
}
}
}
} else { // Catch-all for all other errors
interaction.Audit_Reason__c += ' Reason: Error during Lead insert - ' + error.getMessage() + '.';
System.debug('Error during Lead insert - ' + error.getMessage() + '.');
Expand Down Expand Up @@ -410,7 +412,10 @@ public class INT_InteractionProcessor {
*/
private List<Database.LeadConvert> convertLeads(List<Database.LeadConvert> leadsToConvert) {
List<Database.LeadConvert> leadsToReconvert = new List<Database.LeadConvert>();
Database.LeadConvertResult[] leadConvertResults = Database.convertLead(leadsToConvert, false); // Convert Leads
//Setting DMLOptions to allowSave allows duplicate matching rules that alert rather than block to save results. This allows the standard duplicate account rule to be bypassed.
Database.DMLOptions dml = new Database.DMLOptions();
dml.DuplicateRuleHeader.AllowSave = true;
Database.LeadConvertResult[] leadConvertResults = Database.convertLead(leadsToConvert, dml); // Convert Leads

for (Database.LeadConvertResult lcr : leadConvertResults) {
Interaction__c interaction = (leadIdToInteractionMap.containsKey(lcr.getLeadId())) ? leadIdToInteractionMap.get(lcr.getLeadId()) : null;
Expand Down Expand Up @@ -445,7 +450,7 @@ public class INT_InteractionProcessor {

for (Datacloud.MatchResult matchResult : dupError.getDuplicateResult().getMatchResults()) {
Contact matchedContact;

if (matchResult.getEntityType() == 'Contact'){
for (Datacloud.MatchRecord match : matchResult.getMatchRecords()) {
// We want to use the oldest matched record, it will be the source Contact.
Contact compareContact = (Contact) match.getRecord();
Expand All @@ -454,6 +459,7 @@ public class INT_InteractionProcessor {
matchedContact = compareContact;
}
}
}

// Build new Lead convert with matching records.
if (matchedContact != null) { // NPE handling
Expand Down Expand Up @@ -575,4 +581,4 @@ public class INT_InteractionProcessor {
}
}
}
}
}