Input & Output
Search for duplicates by Field Values
The doSearch(Map<String, Object> objectData, String objectPrefix)
method evaluates the provided field-value pairs against the Plauti Deduplicate search engine to identify potential duplicates. The method uses the input data (objectData
) and the specified object prefix (objectPrefix
) to execute the search, returning a map containing results grouped by object type.
Method Signature
Method Name: doSearch
Map<String, List<dupcheck.dc3SearchResult>> doSearch(Map<String, Object> objectData, String objectPrefix)
Parameters
Type | Variable | Description |
---|---|---|
Map<String, Object> | objectData | A map containing field names and their respective values. |
String | objectPrefix | The ID prefix of the Salesforce object type being searched (e.g., '003 ' for Contact, '001 ' for Account). |
Output
The doSearch(Map<String, Object> objectData, String objectPrefix)
method returns a Map that organizes the search results using the dc3SearchResult
class.
- Class Reference:
Map<String, List<dupcheck.dc3SearchResult>>
Apex Example
This snippet searches for duplicate records in Salesforce based on specified field values using the Plauti Deduplicate API. It initializes the API, executes a search for potential duplicates within the specified object type, and logs the results. If duplicates are found, it processes them by logging object data, matching scores, scenario scores, object names, prefixes, and display fields. If no duplicates are found, it logs a message indicating no matches.
// Define search criteria using a Map with field values for the search
Map<String, Object> objectData = new Map<String, Object>{
'FirstName' => 'John',
'LastName' => 'Doe',
'Email' => '[email protected]'
};
System.debug('Search criteria defined: ' + objectData);
// Specify the object prefix for the Salesforce object type (e.g., '003' for Contact)
String objectPrefix = '003';
System.debug('Object prefix specified for Contact: ' + objectPrefix);
// Initialize the Duplicate Check API to perform the duplicate search
dupcheck.dc3Api dc3Api = new dupcheck.dc3Api();
System.debug('Duplicate Check API initialized.');
// Execute the duplicate search using the provided search criteria and object prefix
System.debug('Executing duplicate search...');
Map<String, List<dupcheck.dc3SearchResult>> results = dc3Api.doSearch(objectData, objectPrefix);
System.debug('Search executed. Results: ' + results);
// Check if duplicates are found and process the results
if (results != null && !results.isEmpty()) {
System.debug('Duplicates found. Processing results...');
// Iterate over each object type prefix in the results
for (String prefix : results.keySet()) {
System.debug('Processing duplicates for object prefix: ' + prefix);
List<dupcheck.dc3SearchResult> duplicates = results.get(prefix);
// Iterate over each duplicate record found
for (dupcheck.dc3SearchResult duplicate : duplicates) {
// Log the duplicate record data
System.debug('Duplicate Record Data (objectData): ' + duplicate.objectData);
// Log the overall matching score between the input and the duplicate record
System.debug('Matching Score: ' + duplicate.Score);
// Log detailed scenario scores showing how each applied scenario contributed to the overall score
for (dupcheck.dc3SearchResult.ScenarioScore scenarioScore : duplicate.scenarioScores) {
System.debug('Scenario ID: ' + scenarioScore.scenarioId +
', Name: ' + scenarioScore.scenarioName +
', Score: ' + scenarioScore.scenarioScore);
}
// Log the object name for the duplicate record
String objectName = duplicate.getObjectName();
System.debug('Object Name: ' + objectName);
// Log the object prefix (e.g., '003' for Contact)
String objPrefix = duplicate.getObjectPrefix();
System.debug('Object Prefix: ' + objPrefix);
// Log display field values as configured in the Duplicate Check setup
Map<String, Object> displayFields = duplicate.getDisplayField();
System.debug('Display Fields: ' + displayFields);
}
}
} else {
// If no duplicates are found, log the result
System.debug('No duplicates found for the given search criteria.');
}
Optional: set a predefined filter and/or scenario ID
By invoking doSearchWithFilter
with a field-value map, object prefix, and filter developer name, you can target a specific subset of records based on criteria defined in your Deduplicate setup.
Method name
Map<String, List<dupcheck.dc3SearchResult>> doSearchWithFilter(
Map<String, Object> objectData,
String objectPrefix,
String filterDeveloperName,
Set<String> scenarioIds
)
Apex example
// Define search criteria using a Map of field values
Map<String, Object> objectData = new Map<String, Object>{
'FirstName' => 'John',
'LastName' => 'Doe',
'Email' => '[email protected]'
};
// Specify the object prefix for Contact
final String objectPrefix = '003';
// Define the predefined filter developer name as configured in Deduplicate Setup
final String filterDeveloperName = 'ContactFilter';
// Define scenario IDs
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 with the predefined filter and multiple scenarios
Map<String, List<dupcheck.dc3SearchResult>> results = dc3Api.doSearchWithFilter(
objectData,
objectPrefix,
filterDeveloperName,
scenarioIds
);
System.debug('Duplicate results: ' + results);
Optional: set a query filter and/or scenario ID
By invoking doSearch
with a field-value map, object prefix, and query filter string, you can dynamically refine search results based on conditions.
Method name
Map<String, List<dupcheck.dc3SearchResult>> doSearch(
Map<String, Object> objectData,
String objectPrefix,
String filter,
Set<String> scenarioIds
)
Apex example
// Define search criteria using a Map with field values
Map<String, Object> objectData = new Map<String, Object>{
'FirstName' => 'John',
'LastName' => 'Doe',
'Email' => '[email protected]'
};
// Specify the object prefix for the Salesforce object (e.g., '003' for Contact)
String objectPrefix = '003';
// Define a query filter to narrow down search results (e.g., matching a specific Account ID)
String filter = "AccountId = '00123456789'";
// Define the set of Duplicate Check scenario IDs to apply during the search
Set<String> scenarioIds = new Set<String>{'a2B3x0000008Abc', 'a2B3x0000008Xyz'};
// Initialize the Plauti Deduplicate API instance
dupcheck.dc3Api dc3Api = new dupcheck.dc3Api();
// Execute the duplicate search using the Map, object prefix, query filter, and scenario IDs
Map<String, List<dupcheck.dc3SearchResult>> results;
try {
results = dc3Api.doSearch(objectData, objectPrefix, filter, scenarioIds);
System.debug('Duplicate search executed successfully. Results: ' + results);
} catch (Exception e) {
System.debug('Error during duplicate search: ' + e.getMessage());
}
Updated 8 days ago