Examples & Use Cases
Before Search Plugin
Base Example Code
global class BasicBeforeSearchPlugin implements dupcheck.dc3PluginInterface {
// Define the event type that this plugin handles.
private static final Set<String> implementedEvents = new Set<String>{ 'SEARCH_BEFORE' };
// Determines if this plugin should handle the given event.
global Boolean isAvailable(dupcheck.dc3Plugin.PluginEventType eventType) {
// Return true if the event type is 'SEARCH_BEFORE'
return implementedEvents.contains(eventType.name());
}
// Main entry point: dispatch the event to the appropriate handler.
global Object execute(dupcheck.dc3Plugin.PluginEventType eventType, Object eventData) {
if (eventType.name() == 'SEARCH_BEFORE') {
// Cast the event data to the appropriate input type and call the handler.
return handleSearchBefore((dupcheck.dc3PluginModel.SearchBeforeInput) eventData);
}
return null;
}
// Handles the SEARCH_BEFORE event.
public dupcheck.dc3PluginModel.SearchBeforeOutput handleSearchBefore(dupcheck.dc3PluginModel.SearchBeforeInput input) {
// Create the output object using the input defaults.
dupcheck.dc3PluginModel.SearchBeforeOutput output = new dupcheck.dc3PluginModel.SearchBeforeOutput(input);
// Insert your custom logic here to modify:
// Return the modified output.
return output;
}
}
Example 1: Disable Cross Object search in DC Entry
This example demonstrates how to disable cross-object search when the search is triggered on entry. In this case, if the feature list includes the “ON_ENTRY” trigger and the record is a Lead (prefix “00Q”), the plugin sets the cross-object search flag to false.
global class BeforeSearchPlugin_DisableCrossObject implements dupcheck.dc3PluginInterface {
// Only handle the SEARCH_BEFORE event.
private static Set<String> implementedEvents = new Set<String>{ 'SEARCH_BEFORE' };
global Boolean isAvailable(dupcheck.dc3Plugin.PluginEventType eventType) {
return BeforeSearchPlugin_DisableCrossObject.implementedEvents.contains(eventType.name());
}
global Object execute(dupcheck.dc3Plugin.PluginEventType eventType, Object eventData) {
if (eventType.name() == 'SEARCH_BEFORE') {
return handleSearchBefore((dupcheck.dc3PluginModel.SearchBeforeInput) eventData);
}
return null;
}
// This method is invoked before the index search executes.
public dupcheck.dc3PluginModel.SearchBeforeOutput handleSearchBefore(dupcheck.dc3PluginModel.SearchBeforeInput input) {
// Instantiate the output using the default values from the input.
dupcheck.dc3PluginModel.SearchBeforeOutput output = new dupcheck.dc3PluginModel.SearchBeforeOutput(input);
// Check if the current feature includes 'ON_ENTRY' and the object is a Lead.
if (input.feature.contains('ON_INSERT') && input.objectPrefix == '00Q') {
// Disable cross-object search for this context.
output.crossObjectSearch = false;
System.debug('Cross-object search disabled for ON_INSERT for Lead records.');
}
// Return the modified output.
return output;
}
}
Example 2: Search with a specific scenario based on record context
This plugin intercepts the duplicate search process before the index search is executed and determines which exclusive search scenario to apply based on the Lead Source field. If the Lead Source is “Web,” it clears any predefined scenarios and applies the Web scenario exclusively. If the Lead Source is “Phone Inquiry,” it does the same with the Phone Inquiry scenario. This ensures that the duplicate search process uses the appropriate scenario tailored to the lead’s source.
global class BeforeSearchPluginScenarioByLeadSource implements dupcheck.dc3PluginInterface {
// Define the event type this plugin handles.
private static Set<String> implementedEvents = new Set<String>{ 'SEARCH_BEFORE' };
// Check if this plugin should process the given event.
global Boolean isAvailable(dupcheck.dc3Plugin.PluginEventType eventType) {
return BeforeSearchPluginScenarioByLeadSource.implementedEvents.contains(eventType.name());
}
// Main entry point: dispatch the SEARCH_BEFORE event to our handler.
global Object execute(dupcheck.dc3Plugin.PluginEventType eventType, Object eventData) {
if (eventType.name() == 'SEARCH_BEFORE') {
return handleSearchBefore((dupcheck.dc3PluginModel.SearchBeforeInput) eventData);
}
return null;
}
public dupcheck.dc3PluginModel.SearchBeforeOutput handleSearchBefore(dupcheck.dc3PluginModel.SearchBeforeInput input) {
// Create the output object using the input defaults.
dupcheck.dc3PluginModel.SearchBeforeOutput output = new dupcheck.dc3PluginModel.SearchBeforeOutput(input);
// Process only if the record is a Lead (object prefix '00Q').
if (input.objectPrefix == '00Q') {
// Query the Lead record to get an up-to-date LeadSource field value.
Lead queriedLead = [SELECT Id, LeadSource FROM Lead WHERE Id = :String.valueOf(input.objectData.get('Id')) LIMIT 1];
String leadSource = queriedLead.LeadSource;
// Clear any existing scenario IDs to enforce an exclusive scenario.
output.scenarioIdSet.clear();
// Apply an exclusive scenario based on the queried LeadSource value.
if (leadSource != null && leadSource.equalsIgnoreCase('Web')) {
output.scenarioIdSet.add('a0RAW000004Php42AC'); // Replace with your actual scenario ID for "Web"
System.debug('Exclusive scenario set to Web scenario for Lead Source "Web".');
} else if (leadSource != null && leadSource.equalsIgnoreCase('Phone Inquiry')) {
output.scenarioIdSet.add('a0RAW000004Y2hp2AC'); // Replace with your actual scenario ID for "Phone Inquiry"
System.debug('Exclusive scenario set to Phone Inquiry scenario for Lead Source "Phone Inquiry".');
}
}
// Return the modified output containing only the desired scenario.
return output;
}
}
Example 3: Exclude Inactive Contacts
This plugin intercepts the duplicate search process before it executes on Contact records (identified by the ‘003
’ prefix) and appends a filter to exclude records where the custom field Inactive__c is true. By ensuring that only active contacts are considered during the search, it improves the accuracy of duplicate detection by filtering out inactive or outdated records.
global class BeforeSearch_FilterInactiveContacts implements dupcheck.dc3PluginInterface {
// Only handle the SEARCH_BEFORE event.
private static final Set<String> implementedEvents = new Set<String>{ 'SEARCH_BEFORE' };
// Determines if this plugin should process the given event.
global Boolean isAvailable(dupcheck.dc3Plugin.PluginEventType eventType) {
return implementedEvents.contains(eventType.name());
}
// Main entry point: dispatch the SEARCH_BEFORE event to our handler.
global Object execute(dupcheck.dc3Plugin.PluginEventType eventType, Object eventData) {
if(eventType.name() == 'SEARCH_BEFORE') {
return handleSearchBefore((dupcheck.dc3PluginModel.SearchBeforeInput) eventData);
}
return null;
}
public dupcheck.dc3PluginModel.SearchBeforeOutput handleSearchBefore(dupcheck.dc3PluginModel.SearchBeforeInput input) {
// Instantiate the output using default input values.
dupcheck.dc3PluginModel.SearchBeforeOutput output = new dupcheck.dc3PluginModel.SearchBeforeOutput(input);
// Process only if the record is a Contact (object prefix '003').
if (input.objectPrefix == '003') {
// Define the filter condition: include only active contacts.
String filterCondition = 'Inactive__c = false';
// Append the filter condition to any existing filter.
if (String.isBlank(output.filter)) {
output.filter = filterCondition;
} else {
output.filter = '(' + output.filter + ') AND ' + filterCondition;
}
System.debug('BeforeSearch_FilterInactiveContacts: Applied filter - ' + output.filter);
}
return output;
}
}
Updated 17 days ago