How to use Duplicate Check with a Custom Object in Salesforce Lightning

The use of custom objects in Duplicate Check is available in our Advanced and Premium edition.
In this article, you can find out how to integrate Duplicate Check in your custom object. This tutorial is for Salesforce Lightning, if you are using Salesforce Classic please navigate to this article.

Step 1 Add Custom Object to DC Setup

1.1 Navigate to the DC Setup Page and under 'Object Setup' click on 'Add Object'.
1.2 In the list that appears, choose the Custom Object you wish to use. In this example, we are using the custom object 'Price'.
1.3  After clicking 'Add', the object will appear in the Object Setup.
After adding the custom object to the setup, create a scenario to define a strategy for finding duplicate records.

Step 2 Create a custom DC Check button in Salesforce Lightning (optional)

The DC Check button allows you to do a search from the record page layout. After the button is clicked, Duplicate Check will search for duplicate records for that particular record you're working from. Creating the DC Check button is not mandatory. 


2.1 Navigate to the Salesforce Setup - Object Manager. 
2.2 In the Object Manager, find your custom object. Under 'Details' copy the 'API name' of the custom object. 
2.3 Navigate to the 'Buttons, Links and Actions' menu.
2.4 On the top-right of the page, click 'New Button or Link'. 
2.5 Fill out the form using the details in the example below. Copy and paste the code below.
In this example, we are using 'Price' as the *Custom Object*:
Replace *API_NAME* with the API name that corresponds with your custom Object. 

    {!URLFOR('/apex/dupcheck__dc3Check?Id='+*API_NAME*.Id)}
2.6 Click 'Save'. Your DC Check button is now created.

Step 3 Add the DC Check button to your Custom Object Layout (optional)

3.1 To add the DC Check custom button to your custom object page layout navigate to the Salesforce Setup menu.
3.2 Navigate to the Object Manager.
3.3  Now, find and open the Custom Object.
3.4 Navigate to the 'Page Layouts' menu and open the page layout you want to add the DC Check button to. 
3.5  From the 'Mobile & Lightning Actions' menu, drag and drop the 'DC Check' button to the custom button section below, which will be highlighted in green when you drag the button.




Click here to see a short video of this step
3.6  Click 'Save'. You have added the DC Check Custom button to your custom object. Here is an example of how it looks added to the custom object 'Price':

Step 4 Create the DC Merge button in Salesforce Lightning (optional)

4.1 Navigate to the Salesforce Setup - Custom Code - Visualforce Pages. 
4.2 Click 'New'. 
4.3 At 'Label', enter a value, for example, "DC Merge Price". 
4.4 At 'Available for Lightning Experience, Lightning Communities, and the mobile app', set the checkbox to 'true'.
4.5 At 'Visualforce Markup', replace all contents with the markup mentioned below. Make sure to replace "*Object__c*" with the API name of your Custom Object. 

    <apex:page standardController="*Object__c*" extensions="dupcheck.dc3ControllerMergeList" recordSetVar="records" docType="html-5.0" sidebar="false">
    <dupcheck:dc3MergeList records="{!allRecords}" selected="{!selectedRecords}"/>
</apex:page>
4.6 Press Save. 
4.7 Now navigate to the Object Manager - Custom object - Buttons, Links, and Actions. 
4.8 Click 'New Button or Link'. 
4.9 At 'Label' enter a value, for example, "DC Merge". This is the label of the button the users see in the User Interface.
4.10 At 'Display type', choose 'List Button'. The checkbox at 'Display checkboxes' should be set to 'true'. 
4.11 At 'Behavior', choose 'Display in existing window with sidebar'. 
4.12 At 'Content source', choose 'Visualforce Page'.
4.13 At 'Content', find the new Visualforce Page we just created. 
4.13 Press Save. 


Step 5 Add the "DC Merge" button to your page layout (optional)

5.1 Navigate to the Salesforce Setup - Object Manager - Your custom object - Search Layouts for Salesforce Classic. 
5.2 At 'List View', click 'Edit'. 
5.3 Move the 'DC Merge' button from 'Available Buttons' to 'Selected Buttons'. 
5.4 Click Save. 

Step 6 Create a 'Disable Duplicate Check' checkbox in Salesforce Lightning (mandatory)

6.1 Navigate to the Salesforce Setup - Object Manager. 
6.2 Find the custom object you want to use. Under 'Details' copy the API name of the *Object*.

6.3  Navigate to the 'Fields & Relationships' page.
6.4  On the top right click on the 'New' button. 
6.5 Under 'Data Type' select the 'Checkbox' and then click 'Next' 
6.6 Enter the following settings and click 'Next'

Field Label: Disable Duplicate Check
Field Name: dc3DisableDuplicateCheck

6.7 Depending on your Salesforce edition (Professional and up), you will now get a screen to establish field-level security. Decide who may see the Disable Duplicate Check button and click 'Next'. 
6.8 Depending on your Salesforce edition (Professional and up), you will now get a screen where you are able to add the Disable Duplicate Check button to the page layout. Add the button to the pages you would like. 
6.9 Click 'Save'. Your 'Disable Duplicate Check' checkbox is now created. 
As per Salesforce policy, you first need to create the Apex Trigger and Test Class in your sandbox and then deploy from sandbox to production.

Step 7 Create the Apex Trigger (mandatory)

7.1  Navigate to the 'Salesforce Setup' and search for Object Manager in the search bar.
7.2 Now when you are in the Object Manager, find the custom object you want to use and click on it. Under 'Details' copy the API name of the *Object*.

7.3  Navigate to the 'Triggers' page.
7.4  On the top right click on the 'New' button. 
7.5 Replace all code in the box with the Apex Trigger code below. Make sure you replace *OBJECT_NAME* and *OBJECT_API_NAME* with the name and API name of your Custom Object.

The Test Class part should be created as an Apex Class (Salesforce Setup > Custom Code > Apex Classes

Click here to watch a short video of this step.

    trigger dc3*OBJECT_NAME*Trigger on *OBJECT_API_NAME*(after delete, after insert, after undelete, after update, before insert, before update) { 

    dupcheck.dc3Trigger triggerTool = new dupcheck.dc3Trigger(trigger.isBefore, trigger.isAfter, trigger.isInsert, trigger.isUpdate, trigger.isDelete, trigger.isUndelete);
    String errorString = triggerTool.processTrigger(trigger.oldMap, trigger.new); 

    if (String.isNotEmpty(errorString)) { trigger.new[0].addError(errorString,false); } 
}


// TEST CLASS BELOW

@isTest
private class TestDC*OBJECT_NAME* {
	
   static testMethod void Test_Insert*OBJECT_NAME*() {
	*OBJECT_API_NAME* p = new *OBJECT_API_NAME*();
	// Add all fields which are required to insert the record. For example;
	// p.Name = 'Testprice';
	// p.Price__c = 110.0;	
		
	insert p;
	system.assertEquals(true, p.Id != null);
   }
}
This is an example of the code with the custom object 'Price'.

    trigger dc3PriceTrigger on PRICE__c(after delete, after insert, after undelete, after update, before insert, before update) { 

    dupcheck.dc3Trigger triggerTool = new dupcheck.dc3Trigger(trigger.isBefore, trigger.isAfter, trigger.isInsert, trigger.isUpdate, trigger.isDelete, trigger.isUndelete);
    String errorString = triggerTool.processTrigger(trigger.oldMap, trigger.new); 

    if (String.isNotEmpty(errorString)) { trigger.new[0].addError(errorString,false); } 
}


// TEST CLASS BELOW

@isTest
private class TestDCPrice {
	
   static testMethod void Test_InsertPrice() {
	Price__c p = new Price();
	// Add all fields which are required to insert the record. For example;
	// p.Name = 'Testprice';
	// p.Price__c = 110.0;	
		
	insert p;
	system.assertEquals(true, p.Id != null);
   }
}
7.6  Click 'Save'. The Trigger is created successfully
Now, make sure to create a scenario and apply the DC Check features to it. Learn more about scenarios in this article.
 

Having trouble?

Our support agents are ready to help you !