Using the Before Search Plugin

Before Search Plugin

This article explains how to extend Duplicate Check’s candidate record search process by implementing the Before Search Plugin. You can use this plugin to run custom logic before Duplicate Check performs its candidate record search—tailoring the search input, filters, and scenario selection based on context provided by the system.

Overview

The Before Search Plugin allows you to modify the search input data before the index search is executed.

  • Refine Filters: Adjust the default search filter to, for example, restrict results only to records owned by the current user.
  • Override Scenarios: Modify or override the set of search scenarios based on user roles or record context.
  • Enrich Data: Add or update fields on the source record so that the duplicate search can match on more accurate or derived data.
  • Control Cross-Object Search: Enable or disable search across multiple object types based on the record’s properties.
flowchart TD
    A[Duplicate Search Invoked] --> B[**Invoke Before Search Plugin**: Modify Input Data]
    B --> C[Index Search Execution with Modified Input]
    C --> D[Candidate Records Identified]

Execute on Supported Methods

These supported methods allow you to filter when the Before Search Plugin executes its custom logic. When a specific method (such as ON_LAYOUT, ON_SEARCH, etc.) is set in the input, the plugin only runs its custom filter adjustments in that context. If no method is specified, the plugin may apply its logic universally for every search operation.

Method NameDescription
ON_LAYOUTTriggered during DC Live when a record layout is loaded.
ON_SEARCHTriggered when searching with DC Search
ON_UPLOADTriggered during bulk insert operations.
ON_SINGLEUPLOADTriggered during API or Apex insert operations.
ON_CHECKTriggered when using DC Check functionality.
ON_CONVERTTriggered during DC Convert (lead conversion).
ON_WEB2LEADTriggered when the web-to-lead checkbox is used on a webform.
ON_RVUPDATETriggered during RV Entry.
ON_INSERT; ON_UPDATETriggered during DC Entry.
ON_FLOWTriggered during a Flow search.
ON_DATAAPITriggered when using the Data API.

Implementation

To implement the Before Search Plugin, create an Apex class that implements the dupcheck.dc3PluginInterface. Your class will primarily handle the SEARCH_BEFORE event using a dedicated method (for example, handleSearchBefore).

global Object execute(dupcheck.dc3Plugin.PluginEventType eventType, Object eventData)
Step 1. Create Apex Class

Ensure your class is declared as global so that it can be referenced by the Duplicate Check framework.

Step 2. Implement the `isAvailable` Method
  • eventType: The event triggering the plugin. Verify that it is 'SEARCH_BEFORE'.
  • This method returns true if the plugin should handle the given event.
Step 3. Implement the `execute` Method
  • This method dispatches the event to a dedicated handler (for example, handleSearchBefore).
  • Only events of type SEARCH_BEFORE are processed.
Step 4. Implement the handleSearchBefore Method
  • Receive an instance of dupcheck.dc3PluginModel.SearchBeforeInput, which provides the source record data, default search filter, a list of search scenarios, and a flag indicating whether cross-object search is enabled.
  • Insert your custom logic to modify the search input. For example, you might adjust the filter so that only records owned by the current user are returned, or override the default search scenarios based on the current context.
  • Return an instance of dupcheck.dc3PluginModel.SearchBeforeOutput that includes your updated search filter, revised scenario identifier set, and any enriched data.
Step 5. Reference the Plugin in DC Settings

In your Salesforce org, navigate to the Duplicate Check Setup page and open the DC Settings section. Under the “Before Search Plugin” field, enter the fully qualified name of your custom Apex class (for example, BeforeSearchPlugin). This registration ensures that the Duplicate Check framework uses your implementation to tailor the search input before executing the index search.