Examples & Use Cases

Search Plugin

Below are example implementations of the Plauti Deduplicate Search Plugin, each demonstrating a different use case.

Basic Example Code

This example shows how to implement the dupcheck.dc3Plugin.InterfaceSearch for your custom class.

global class DefaultSearch implements dupcheck.dc3Plugin.InterfaceSearch {
    global void processResults(String methodName, Id sourceId, Map<String, List<dc3SearchResult>> searchResults) {
      
        // YOUR CUSTOM CODE
        
        // Log basic metadata
        System.debug('Search initiated from method: ' + methodName);
        System.debug('Source Record Id: ' + sourceId);
        
        // Loop through the search results and log duplicate counts for each object type.
        for (String objectPrefix : searchResults.keySet()) {
            List<dc3SearchResult> results = searchResults.get(objectPrefix);
            System.debug('Object Prefix: ' + objectPrefix + ' has ' + results.size() + ' duplicate(s).');
        }
        
        // Additional custom logic can be added here based on the methodName.
        // For example, you could branch your logic as follows:
        /*
        if (methodName.equalsIgnoreCase('ON_LAYOUT')) {
            // Execute logic specific to DC Live.
        } else if (methodName.equalsIgnoreCase('ON_SEARCH')) {
            // Execute logic for searching executed via DC search.
        }
        // And so on for the other supported methods.
        */
        
        return;
    }
}

Example 1: Audit logging plugin

This example logs key metadata about every duplicate search for audit and debugging purposes.

global class AuditLoggingSearchPlugin implements dupcheck.dc3Plugin.InterfaceSearch {
    global void processResults(String methodName, Id sourceId, Map<String, List<dc3SearchResult>> searchResults) {
        // Log the search context and metadata
        System.debug('Audit Logging - Search initiated from method: ' + methodName);
        System.debug('Source Record Id: ' + sourceId);
        
        // Log duplicate count per object type
        if (searchResults != null && !searchResults.isEmpty()) {
            for (String objectPrefix : searchResults.keySet()) {
                List<dc3SearchResult> results = searchResults.get(objectPrefix);
                System.debug('Object Prefix: ' + objectPrefix + ' returned ' + results.size() + ' duplicate(s).');
            }
        } else {
            System.debug('No duplicate results found.');
        }
        return;
    }
}

Example 2: Duplicate flagging plugin

This use case updates a custom field on the source record (for example, Duplicate_Flag_c) if duplicates are found. This flag can be used elsewhere in your business process.

global class DuplicateFlaggingSearchPlugin implements dupcheck.dc3Plugin.InterfaceSearch {
    global void processResults(String methodName, Id sourceId, Map<String, List<dc3SearchResult>> searchResults) {
        if (sourceId == null) return;
        
        // Check if duplicates are found for a specific object (e.g., Lead with key prefix '00Q')
        if (sourceId.getSobjectType().getDescribe().getKeyPrefix().equalsIgnoreCase('00Q')) {
            List<dc3SearchResult> duplicates = searchResults.get('00Q');
            if (duplicates != null && !duplicates.isEmpty()) {
                // Query the source record (assuming it's a Lead) and update a custom flag field
                Lead leadRecord = [SELECT Id, Duplicate_Flag__c FROM Lead WHERE Id = :sourceId LIMIT 1];
                leadRecord.Duplicate_Flag__c = true;
                try {
                    update leadRecord;
                    System.debug('Duplicate flag set on Lead ' + sourceId);
                } catch (DmlException e) {
                    System.debug(LoggingLevel.ERROR, 'Error updating duplicate flag: ' + e.getMessage());
                }
            }
        }
        return;
    }
}

Example 3: Custom notification plugin

This example sends a custom notification (displayed in the Salesforce notification bell) to the record owner when duplicates are detected. Make sure you have a custom notification type (e.g., with DeveloperName Duplicate_Found) created in your org.

global class NotificationSearchPlugin implements dupcheck.dc3Plugin.InterfaceSearch {
    global void processResults(String methodName, Id sourceId, Map<String, List<dc3SearchResult>> searchResults) {
        if (sourceId == null) return;
        
        // Process only for Lead records (key prefix '00Q') for this example
        if (sourceId.getSobjectType().getDescribe().getKeyPrefix().equalsIgnoreCase('00Q')) {
            List<dc3SearchResult> duplicates = searchResults.get('00Q');
            if (duplicates != null && !duplicates.isEmpty()) {
                // Retrieve the Lead's owner
                Lead leadRecord = [SELECT OwnerId FROM Lead WHERE Id = :sourceId LIMIT 1];
                Id ownerId = leadRecord.OwnerId;
                
                // Query the Custom Notification Type using its API name "Duplicate_Found"
                CustomNotificationType cnt = [SELECT Id FROM CustomNotificationType WHERE DeveloperName = 'Duplicate_Found' LIMIT 1];
                
                // Build the custom notification
                Messaging.CustomNotification notification = new Messaging.CustomNotification();
                notification.setNotificationTypeId(cnt.Id);
                notification.setTitle('Duplicate Found on Lead');
                notification.setBody('Duplicates were detected for Lead ' + sourceId + '. Please review.');
                notification.setTargetId(sourceId);
                notification.setSenderId(UserInfo.getUserId());
                
                // Send the notification to the owner
                // The send() method accepts a set of recipient Ids
                notification.send(new Set<String>{ownerId});
            }
        }
        return;
    }
}