Examples & Use Cases

Direct Processing Plugin

Basic Example Code

global class BasicDirectProcessingPlugin implements dupcheck.dc3PluginInterface {
    
    // Define the events handled by this plugin.
    private static Set<String> implementedEvents = new Set<String>{ 'DIRECT_PROCESS_BEFORE' };

    // Check if the plugin should process this event.
    global Boolean isAvailable(dupcheck.dc3Plugin.PluginEventType eventType) {
        return implementedEvents.contains(eventType.name());
    }

    // Main entry point for the plugin logic.
    global Object execute(dupcheck.dc3Plugin.PluginEventType eventType, Object eventData) {
        switch on eventType {
            when DIRECT_PROCESS_BEFORE {
                return processDirectBefore((dupcheck.dc3PluginModel.DirectProcessBeforeInput) eventData);
            }
            when else {
                return null;
            }
        }
    }

    // Handle the DIRECT_PROCESS_BEFORE event.
    public dupcheck.dc3PluginModel.DirectProcessBeforeOutput processDirectBefore(dupcheck.dc3PluginModel.DirectProcessBeforeInput input) {
        // TODO: Add your custom processing logic here.

        // Build the output based on input, which instructs DC how to continue.
        dupcheck.dc3PluginModel.DirectProcessBeforeOutput output =
            new dupcheck.dc3PluginModel.DirectProcessBeforeOutput(input);
        return output;
    }
}

Example 1: Exclude high profile Leads from Direct Processing and store in a DC Job for manual review

For a Lead, if its LeadSource equals “Partner Referral” and its AnnualRevenue is equal to or exceeds 10 million, it prevents automatic merging and conversion by setting doMerge and doConvert to false. It also flags the record to be stored as a DC Job for manual review. If the criteria aren’t met, the plugin allows normal processing to continue.

global class DirectProcessingPlugin implements dupcheck.dc3PluginInterface {
    // Allowed event type for this plugin.
    private static final Set<String> IMPLEMENTED_EVENTS = new Set<String>{ 'DIRECT_PROCESS_BEFORE' };
    
    global Boolean isAvailable(dupcheck.dc3Plugin.PluginEventType eventType) {
        // Check if the event type is supported.
        return IMPLEMENTED_EVENTS.contains(eventType.name());
    }

    global Object execute(dupcheck.dc3Plugin.PluginEventType eventType, Object eventData) {
        // Process only DIRECT_PROCESS_BEFORE events.
        if (eventType.name() == 'DIRECT_PROCESS_BEFORE') {
            return handleDirectProcessBefore((dupcheck.dc3PluginModel.DirectProcessBeforeInput) eventData);
        }
        return null;
    }

    private dupcheck.dc3PluginModel.DirectProcessBeforeOutput handleDirectProcessBefore(dupcheck.dc3PluginModel.DirectProcessBeforeInput input) {
        // Query the Lead record to get the latest LeadSource and AnnualRevenue values.
        String leadSource;
        Decimal annualRevenue;
        try {
            Lead queriedLead = [SELECT LeadSource, AnnualRevenue FROM Lead WHERE Id = :input.objectData.Id LIMIT 1];
            leadSource = queriedLead.LeadSource;
            annualRevenue = queriedLead.AnnualRevenue;
        } catch(Exception ex) {
            leadSource = null;
            annualRevenue = 0;
        }
        
        // Initialize the output object with default flags from input.
        dupcheck.dc3PluginModel.DirectProcessBeforeOutput output = new dupcheck.dc3PluginModel.DirectProcessBeforeOutput(input);
        
        // Check if the record is a Lead.
        if (input.objectData.getSObjectType() == Lead.SObjectType) {
            // If LeadSource is "Partner Referral" and AnnualRevenue is higher than 10 million,
            // disable auto merge/convert and store as a DC Job for manual review.
            if (leadSource != null && leadSource.equalsIgnoreCase('Partner Referral') && annualRevenue != null && annualRevenue >= 10000000) {
                System.debug('High profile Partner Referral Lead: AnnualRevenue = ' + annualRevenue + '. Storing result as a DC Job for manual review.');
                output.doConvert = false;
                output.doMerge = false;
                output.storeAsJob = true;
            } else {
                System.debug('Lead does not meet high profile Partner Referral criteria. Processing will continue automatically.');
            }
        }
        return output;
    }
}