Input & Output
Search using an ID
The doSearch(Id objectId)
method identifies potential duplicates by evaluating the data of an existing Salesforce record. It uses the Plauti Deduplicate search engine to return results grouped by object type. This method is ideal for searching with minimal input, relying on the Id
of a record stored in Salesforce.
Method Signature
Method Name: doSearch
Map<String, List<dupcheck.dc3SearchResult>> doSearch(Id objectId)
Parameters
Type | Variable | Description |
---|---|---|
Id |
|
|
Output
The doSearch(Id objectId)
method returns a Map that organizes the search results using the dc3SearchResult
class.
- Class Reference:
Map<String, List<dupcheck.dc3SearchResult>>
Apex Example
This snippet checks for duplicate Contact records using the Plauti Deduplicate API. It queries potential duplicates for a given Contact ID, logs the search results, and processes them if any matches are found. It records the matching score, duplicate record data, scenario scores, object names, object prefixes, and display fields. If no duplicates are found, it logs that information.
// Define the ID of an existing Contact record for duplicate checking
final Id contactId = '003J8000007jigQIAQ';
System.debug('Starting duplicate search for Contact ID: ' + contactId);
// Initialize the Duplicate Check API instance
final dupcheck.dc3Api dc3Api = new dupcheck.dc3Api();
// Execute the duplicate search using the provided Contact ID
Map<String, List<dupcheck.dc3SearchResult>> results;
try {
results = dc3Api.doSearch(contactId); // Perform the duplicate search
System.debug('Duplicate search executed.');
} catch (Exception e) {
// Log any errors during the search execution
System.debug('Error during duplicate search: ' + e.getMessage());
return;
}
// Process and log the search results
if (results != null && !results.isEmpty()) {
// Loop through each object type prefix in the search results
for (String objectPrefix : results.keySet()) {
List<dupcheck.dc3SearchResult> duplicates = results.get(objectPrefix);
// Iterate over each duplicate found
for (dupcheck.dc3SearchResult duplicate : duplicates) {
// Log the overall matching score (0-100) for the duplicate
System.debug('Matching Score: ' + duplicate.Score);
// Log the full duplicate record data (objectData)
System.debug('Duplicate Record Data: ' + duplicate.objectData);
// Log detailed scenario scores that contributed to the overall match score
for (dupcheck.dc3SearchResult.ScenarioScore scenarioScore : duplicate.scenarioScores) {
System.debug('Scenario ID: ' + scenarioScore.scenarioId +
', Name: ' + scenarioScore.scenarioName +
', Score: ' + scenarioScore.scenarioScore);
}
// Log the object name (e.g., "Contact") of the duplicate record
System.debug('Object Name: ' + duplicate.getObjectName());
// Log the object prefix (e.g., '003' for Contact, '001' for Account)
System.debug('Object Prefix: ' + duplicate.getObjectPrefix());
// Log result fields configured in DC Setup
System.debug('Display Fields: ' + duplicate.getDisplayField());
}
}
} else {
// Log if no duplicates were found for the given Contact ID
System.debug('No duplicates found for Contact ID: ' + contactId);
}
Optional: set a filter
By invoking doSearchWithFilter
, you can specify a filter to narrow down search results based on criteria defined in your Deduplicate setup.
Method name
Map<String, List<dupcheck.dc3SearchResult>> doSearchWithFilter(Id objectId, String filterDeveloperName)
Apex example
// Define the ID of the Salesforce record to check for duplicates
final Id recordId = '003J8000007jigQIAQ';
// Specify the predefined filter developer name as configured in Deduplicate Setup
final String filterDeveloperName = 'ContactFilter';
// Initialize the Plauti Deduplicate API instance
final dupcheck.dc3Api dc3Api = new dupcheck.dc3Api();
// Execute the duplicate search using the record ID and predefined filter
Map<String, List<dupcheck.dc3SearchResult>> results = dc3Api.doSearchWithFilter(recordId, filterDeveloperName);
System.debug('Duplicate search results: ' + results);
Updated 8 days ago