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

Last published at: 2022-02-08 12:37:16 UTC
Delete

This tutorial is for Salesforce Classic. If you are using Salesforce Lightning please see this article.

Delete

This feature is available in the Advanced and Premium editions.

Delete

In this tutorial, find out how to add a custom object to DC Object Setup in Salesforce Classic and integrate DC preventions in it.

Step 1 Add custom Object to DC Setup

  1. Navigate to DC Setup Page and under 'Object Setup' click on 'Add Object'.
  2. In the list that will appear, choose the 'Custom Object' you wish to use. In this example, we are using the custom object 'Price'
  3. After clicking 'Add' the object will appear in the Object Menu.

Step 2 Create a custom DC Check button in Salesforce Classic

  1. Navigate to the Salesforce 'Setup' page and search for the 'Objects' page in the search box or look for it manually under Build - Create - Objects.
  2. Now when you are in the 'Objects' page, find the custom object you want to use and click on it. Now under 'Custom Object Definition Detail' copy the API name.
  3. Scroll down to the 'Buttons, Links and Actions' menu. 

    Click on the 'New Button or Link' button.

  4. Fill out the form using the details in the example below. Copy and paste the code below.
    Replace *API_NAME* with the API name that corresponds with your (custom) Object.
    {!URLFOR('/apex/dupcheck__dc3Check?Id='+*API_NAME*.Id)}

  5. Click 'Save'. Your DC Check custom button for Salesforce Classic is created.

Step 3 Add the DC Check button to your custom Object Layout

  1. To add the DC Check custom button to your custom object page layout navigate to the Salesforce 'Setup' menu.
  2. Navigate to the Salesforce 'Setup' page and search for the 'Objects' page in the search box or look for it manually under Build - Create - Objects.
  3. Now, find and open the *Custom Object* to which you wish to add the DC Check button to. For this example, we will use the custom object 'Price'
  4.  Navigate to the 'Page Layouts' menu and click 'Edit' on the '*Object* Layout'.
  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.
  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 custom DC Merge button in Salesforce Classic

  1. Navigate to the Salesforce 'Setup' page and search for the 'Objects' page in the search box or look for it manually under Build - Create - Objects.
  2. Now when you are in the 'Objects' page, find the custom object you want to use and click on it. Under 'Custom Object Definition Detail' you will see the API name of the *Custom Object*. Copy the API name.
  3. Scroll down to the 'Buttons, Links and Actions' menu. 

    Click on the 'New Button or Link' button.

  4. Fill out the form using the details in the example below. Copy and paste the code below. Replace *API_NAME* with the API name that corresponds with your (custom) Object.
    var selRecords = {!GETRECORDIDS($ObjectType.*API_NAME*)}; var url = '/apex/dupcheck__dc3Merge?&ids=' + selRecords; window.location = url;

  5. Click 'Save'. You have added the DC Merge button to your *Custom Object*  

Step 5 Create a 'Disable Duplicate Check' checkbox in Salesforce Classic

  1. Navigate to the Salesforce 'Setup' page and search for the 'Objects' page in the search box or look for it manually under Build - Create - Objects.
  2. Now when you are in the 'Objects' page, find the custom object you want to use and click on it.
  3. Scroll down to 'Custom Fields & Relationships' section and click 'New'
  4. Under 'Data Type' select the 'Checkbox' and then click 'Next'
  5. Enter the following settings and click 'Next' 


    Field Label: Disable Duplicate Check
    Field Name: dc3DisableDuplicateCheck

  6. 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'.
  7. 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. 
  8. Click 'Save'. You have successfully created and added the 'Disable Duplicate Check' checkbox to your custom object layout.
Delete

The Apex Trigger is needed when you are are going to use our prevention features and  Search Index feature with your custom object. You can find a list of all prevention features on our pricing page.

Step 6 Create the Apex Trigger

Click here to watch a short example video with the "Offer" Object, showing the following steps.

  1. Navigate to the Salesforce 'Setup' page and search for the 'Objects' page in the search box or look for it manually under Build - Create - Objects.
  2. Now when you are in the 'Objects' page, find the custom object you want to use and click on it.
  3. Scroll down to the 'Triggers' section and click 'New'.
  4. 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.
    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. Click 'Save'. You have successfully created the Apex Trigger
Delete

Now, make sure to create a scenario and apply the DC Check features to it. Learn more about scenarios in this article.