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

This tutorial is for Salesforce Lightning, if you are using Salesforce Classic please navigate to this article.
This feature is available in our Advanced and Premium edition.
In this tutorial, we are showing how to add a custom object to DC Object Setup in Salesforce Lightning and integrate DC preventions in it.

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 Menu.
Click here to watch a short video of this step.
The creation and integration of the DC Merge button are optional.

Step 2 Create a custom DC Check button in Salesforce Lightning

2.1  Navigate to the 'Salesforce Setup' and search for Object Manager in the search bar.
2.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*.
2.3 Navigate to the 'Buttons, Links and Actions' menu.
2.4  On the top right click on 'New Button or Link' button. 
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.
Click here to see a short video of this step

Step 3 Add the DC Check button to your Custom Object Layout.

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' menu or type it in the search box.
3.3  Now, find and open the *Custom Object* to which you wish to add the DC Check button to or type it in the search box.
3.4  Navigate to the 'Page Layouts' menu and click on the '*Object* Layout'. 
3.5  From the 'Buttons' 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 a 'Disable Duplicate Check' checkbox in Salesforce Lightning

4.1  Navigate to the 'Salesforce Setup' and search for Object Manager in the search bar.
4.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*.

4.3  Navigate to the 'Fields & Relationships' page.
4.4  On the top right click on the 'New' button. 
4.5 Under 'Data Type' select the 'Checkbox' and then click 'Next' 
4.6 Enter the following settings and click 'Next'

Field Label: Disable Duplicate Check
Field Name: dc3DisableDuplicateCheck

4.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'. 
4.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. 
4.9 Click 'Save'. Your 'Disable Duplicate Check' checkbox is now created. 
Click here to watch a short video or this step

Step 5 Create the Apex Trigger

5.1  Navigate to the 'Salesforce Setup' and search for Object Manager in the search bar.
5.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*.

5.3  Navigate to the 'Triggers' page.
5.4  On the top right click on the 'New' button. 
5.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.

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); } 
}
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); } 
}
5.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 !