Created
May 7, 2020 02:16
-
-
Save leoruhland/6fafd8736451aed2df8cda2afbfa1053 to your computer and use it in GitHub Desktop.
This file contains 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
@RestResource(urlMapping='/dedup/*') | |
global with sharing class AAA_DEDUP{ | |
@HttpPost | |
global static List<Contact> findContacts(List<Contact> cons) { | |
List<Contact> cons1 = new List<Contact>(); | |
List<Contact> cons2 = new List<Contact>(); | |
List<Contact> cons3 = new List<Contact>(); | |
List<Contact> cons4 = new List<Contact>(); | |
List<Contact> cons5 = new List<Contact>(); | |
List<Contact> foundContacts = new List<Contact>(); | |
List<Datacloud.FindDuplicatesResult> results1; | |
List<Datacloud.FindDuplicatesResult> results2; | |
List<Datacloud.FindDuplicatesResult> results3; | |
List<Datacloud.FindDuplicatesResult> results4; | |
List<Datacloud.FindDuplicatesResult> results5; | |
for(Integer i = 0; i < cons.size(); i++){ | |
if(cons[i] != null){ | |
if(i<50){ | |
cons1.add(cons[i]); | |
} | |
if(i>=50 && i<100){ | |
cons2.add(cons[i]); | |
} | |
if(i>=100 && i<150){ | |
cons3.add(cons[i]); | |
} | |
if(i>=150 && i<200){ | |
cons4.add(cons[i]); | |
} | |
if(i>=200 && i<250){ | |
cons5.add(cons[i]); | |
} | |
} | |
} | |
try { | |
results1 = Datacloud.FindDuplicates.findDuplicates(cons1); | |
results2 = Datacloud.FindDuplicates.findDuplicates(cons2); | |
results3 = Datacloud.FindDuplicates.findDuplicates(cons3); | |
results4 = Datacloud.FindDuplicates.findDuplicates(cons4); | |
results5 = Datacloud.FindDuplicates.findDuplicates(cons5); | |
} catch (Exception ex) { | |
return null; | |
} | |
// Loop the original cons | |
for (Integer i = 0; i < cons1.size(); i++) { | |
Contact foundCon = null; | |
// Find the first duplicate result with a match result, then use the first match record. | |
for (Datacloud.DuplicateResult dr : results1[i].getDuplicateResults()) { | |
if (dr.matchResults.size() > 0 && dr.getMatchResults()[0].matchRecords.size() > 0) { | |
foundCon = (Contact) dr.getMatchResults()[0].getMatchRecords()[0].getRecord(); | |
break; | |
} | |
} | |
foundContacts.add(foundCon); | |
} | |
for (Integer i = 0; i < cons2.size(); i++) { | |
Contact foundCon = null; | |
// Find the first duplicate result with a match result, then use the first match record. | |
for (Datacloud.DuplicateResult dr : results2[i].getDuplicateResults()) { | |
if (dr.matchResults.size() > 0 && dr.getMatchResults()[0].matchRecords.size() > 0) { | |
foundCon = (Contact) dr.getMatchResults()[0].getMatchRecords()[0].getRecord(); | |
break; | |
} | |
} | |
foundContacts.add(foundCon); | |
} | |
for (Integer i = 0; i < cons3.size(); i++) { | |
Contact foundCon = null; | |
// Find the first duplicate result with a match result, then use the first match record. | |
for (Datacloud.DuplicateResult dr : results3[i].getDuplicateResults()) { | |
if (dr.matchResults.size() > 0 && dr.getMatchResults()[0].matchRecords.size() > 0) { | |
foundCon = (Contact) dr.getMatchResults()[0].getMatchRecords()[0].getRecord(); | |
break; | |
} | |
} | |
foundContacts.add(foundCon); | |
} | |
for (Integer i = 0; i < cons4.size(); i++) { | |
Contact foundCon = null; | |
// Find the first duplicate result with a match result, then use the first match record. | |
for (Datacloud.DuplicateResult dr : results4[i].getDuplicateResults()) { | |
if (dr.matchResults.size() > 0 && dr.getMatchResults()[0].matchRecords.size() > 0) { | |
foundCon = (Contact) dr.getMatchResults()[0].getMatchRecords()[0].getRecord(); | |
break; | |
} | |
} | |
foundContacts.add(foundCon); | |
} | |
for (Integer i = 0; i < cons5.size(); i++) { | |
Contact foundCon = null; | |
// Find the first duplicate result with a match result, then use the first match record. | |
for (Datacloud.DuplicateResult dr : results5[i].getDuplicateResults()) { | |
if (dr.matchResults.size() > 0 && dr.getMatchResults()[0].matchRecords.size() > 0) { | |
foundCon = (Contact) dr.getMatchResults()[0].getMatchRecords()[0].getRecord(); | |
break; | |
} | |
} | |
foundContacts.add(foundCon); | |
} | |
return foundContacts; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment