Input & Output

Search for duplicates by SObject

The doSearch(SObject objectData) method evaluates the provided SObject instance against the Plauti Deduplicate search engine to identify potential duplicates. The method uses the field values of the input SObject to execute the search and returns a map containing the results grouped by object type.

Method Signature

Method Name: doSearch

Map<String, List<dupcheck.dc3SearchResult>> doSearch(SObject objectData)

Parameters

Type

Variable

Description

SObject

objectData

  • An SObject instance containing the field values to be used as search criteria.
  • The search logic and the calculated matching score is determined by the applied Plauti Deduplicate scenario.

Output

The doSearch(SObject objectData) method returns a Map that organizes the search results using the dc3SearchResult class.

Apex Example

This snippet checks for duplicate Contact records in Salesforce using the Plauti Deduplicate API. It creates a Contact object with specific field values, executes a duplicate search, and logs the results. If duplicates are found, it processes them by logging the object prefix, matching scores, duplicate record details, scenario scores, object names, and display fields. If no duplicates are found, it logs a message indicating no matches.

// Define an SObject instance with field values
final Contact objectData = new Contact(
    FirstName = 'John',
    LastName = 'Doe',
    Email = '[email protected]'
);
System.debug('Input Contact Object created: ' + objectData);

// Initialize the Duplicate Check API
final dupcheck.dc3Api dc3Api = new dupcheck.dc3Api();
System.debug('Executing doSearch with the Contact object...');

// Execute the duplicate search
Map<String, List<dupcheck.dc3SearchResult>> results;
try {
    results = dc3Api.doSearch(objectData);
    System.debug('Duplicate search executed successfully.');
} catch (Exception e) {
    System.debug('Error during duplicate search: ' + e.getMessage());
    return;
}

// Check if duplicates are found
if (results != null && !results.isEmpty()) {
    System.debug('Duplicates found. Processing results...');

    // Loop through each object prefix in the results
    for (String objectPrefix : results.keySet()) {
        List<dupcheck.dc3SearchResult> duplicates = results.get(objectPrefix);
        System.debug('Object Prefix: ' + objectPrefix + ' | Duplicates Found: ' + duplicates.size());

        for (dupcheck.dc3SearchResult duplicate : duplicates) {
            // Log the matching score
            System.debug('Matching Score: ' + duplicate.Score);

            // Log the duplicate record data
            System.debug('Duplicate Record Data: ' + duplicate.objectData);

            // Log scenario scores
            for (dupcheck.dc3SearchResult.ScenarioScore scenarioScore : duplicate.scenarioScores) {
                System.debug('Scenario ID: ' + scenarioScore.scenarioId + 
                             ' | Scenario Name: ' + scenarioScore.scenarioName + 
                             ' | Scenario Score: ' + scenarioScore.scenarioScore);
            }

            // Log the object name and prefix
            System.debug('Object Name: ' + duplicate.getObjectName());
            System.debug('Object Prefix: ' + duplicate.getObjectPrefix());

            // Log the display fields
            System.debug('Display Fields: ' + duplicate.getDisplayField());
        }
    }
} else {
    System.debug('No duplicates found for the input Contact object.');
}

Optional: set a filter and/or scenario ID

By invoking doSearchWithFilter, you can specify a filter to narrow down search results based on criteria defined in your Deduplicate setup. Also, it is possible to define a specific scenario ID that should be used in the search.

Method Name

Map<String, List<dupcheck.dc3SearchResult>> doSearchWithFilter(
    SObject objectData, 
    String filterDeveloperName, 
    Set<String> scenarioIds
)

Apex Example

// Define an SObject record (e.g., a Contact) with field values for duplicate detection
final Contact contactData = new Contact(
    FirstName = 'John',
    LastName  = 'Doe',
    Email     = '[email protected]'
);

// Specify the predefined filter developer name as configured in Deduplicate Setup
final String filterDeveloperName = 'ContactFilter';

// Define the set of scenario IDs to apply during the duplicate search
final Set<String> scenarioIds = new Set<String>{ 'a2B3x0000008Abc', 'a2B3x0000008Xyz' };

// Initialize the Plauti Deduplicate API instance
final dupcheck.dc3Api dc3Api = new dupcheck.dc3Api();

// Execute the duplicate search using the SObject, the predefined filter, and scenario IDs
Map<String, List<dupcheck.dc3SearchResult>> results = dc3Api.doSearchWithFilter(
    contactData, 
    filterDeveloperName, 
    scenarioIds
);

System.debug('Duplicate search results: ' + results);