What should I do to make Duplicates Migration to Salesforce Classic Successful?

Trujay handles the migration of duplicates to Salesforce for the following modules:

  1. Accounts
  2. Contacts
  3. Leads

To have them migrated successfully to Salesforce Classic, you should proceed with some steps in your Salesforce Classic platform.

Firstly, you should log in to your Salesforce Classic platform. Then, choose Setup button :

salesforce_setup

Then, choose Develop on the left sidebar:

 

salesforce_develop

Then, choose Apex Triggers from a drop-down list on the left sidebar:

apex_triggers

Then, press the Developer console button. When the Developer console window will open - press File -> New -> Apex Trigger:

developer_console

Then, the window New Apex Trigger will open, and you should name it "AccountDuplicateTrigger" and choose the sObject Account from a drop-down list; and press Submit:

account_duplicate_trigger

Then, the window with the initial trigger code will open - you should replace it with a new code (we will provide the code below so you can copy it and paste into that window):

new_code

new_code_2

The code you should copy for the Accounts:

trigger AccountDuplicateTrigger on Account (before insert, before update) {
try {
for (Account account : Trigger.new) {
List<Account> accountList = new List<Account>();
accountList.add(account);

Datacloud.FindDuplicatesResult[] results = Datacloud.FindDuplicates.findDuplicates(accountList);

List<String> duplicateRecords = new List<String>();

for (Datacloud.FindDuplicatesResult findDupeResult : results) {
for (Datacloud.DuplicateResult dupeResult : findDupeResult.getDuplicateResults()) {
for (Datacloud.MatchResult matchResult : dupeResult.getMatchResults()) {
for (Datacloud.MatchRecord matchRecord : matchResult.getMatchRecords()) {
duplicateRecords.add(matchRecord.getRecord().Id);
}
}
}
}

if (duplicateRecords.size() != 0) {
account.addError('Duplicate! Records Ids: ' + string.join(duplicateRecords, ','));
}
}
} catch(exception e) {
// No active duplicate rules are defined for the Account object type
}
}

Note: make sure you copied the code correctly - it affects your CRM directly.

And, finally, make sure to Save the new trigger code:

new_code_3

To check if the new trigger was saved, return to the Apex Triggers to see it (it will have the name you gave it - AccountDuplicateTrigger) :

new_code_4

To proceed with the successful migration of Contacts duplicates, you should repeat the same steps, but name the new trigger "ContactDuplicateTrigger" and choose from a drop-down list the sObject Contact.

The code you should copy and paste in the trigger code window is the following:

trigger ContactDuplicateTrigger on Contact (before insert, before update) {
try {
for (Contact contact : Trigger.new) {
List<Contact> contactList = new List<Contact>();
contactList.add(contact);

Datacloud.FindDuplicatesResult[] results = Datacloud.FindDuplicates.findDuplicates(contactList);

List<String> duplicateRecords = new List<String>();

for (Datacloud.FindDuplicatesResult findDupeResult : results) {
for (Datacloud.DuplicateResult dupeResult : findDupeResult.getDuplicateResults()) {
for (Datacloud.MatchResult matchResult : dupeResult.getMatchResults()) {
for (Datacloud.MatchRecord matchRecord : matchResult.getMatchRecords()) {
duplicateRecords.add(matchRecord.getRecord().Id);
}
}
}
}

if (duplicateRecords.size() != 0) {
contact.addError('Duplicate! Records Ids: ' + string.join(duplicateRecords, ','));
}
}
} catch(exception e) {}
}

To proceed with the successful migration of Leads duplicates, you should repeat the same steps, but name the new trigger "LeadDuplicateTrigger" and choose from a drop-down list the sObject Lead.

The code you should copy and paste in the trigger code window is the following:

trigger LeadDuplicateTrigger on Lead (before insert, before update) {
try {
for (Lead lead : Trigger.new) {
List<Lead> leadList = new List<Lead>();
leadList.add(lead);

Datacloud.FindDuplicatesResult[] results = Datacloud.FindDuplicates.findDuplicates(leadList);

List<String> duplicateRecords = new List<String>();

for (Datacloud.FindDuplicatesResult findDupeResult : results) {
for (Datacloud.DuplicateResult dupeResult : findDupeResult.getDuplicateResults()) {
for (Datacloud.MatchResult matchResult : dupeResult.getMatchResults()) {
for (Datacloud.MatchRecord matchRecord : matchResult.getMatchRecords()) {
duplicateRecords.add(matchRecord.getRecord().Id);
}
}
}
}

if (duplicateRecords.size() != 0) {
lead.addError('Duplicate! Records Ids: ' + string.join(duplicateRecords, ','));
}
}
} catch(exception e) {}
}

If you still cannot do it by yourself or something is not working for you, feel free to contact our CRM expert to walk you through all the steps or to provide the tech help for you.