Performs rule-based searches for duplicate records.
The input is an array of sObject, each of which specifies the values to search for and the type of object that supplies the duplicate rules. The output identifies the detected duplicates for each object that supplies the duplicate rules. findDuplicates() applies the rules to the values to do the search. The output identifies the detected duplicates for each sObject.
Use findDuplicates() to apply duplicate rules associated with an object to values specified by each sObject. Each sObject also has a type that corresponds to an object.
findDuplicates() uses the duplicate rules for the object that has the same type as the sObject. For example, if the sObject type is Account, findDuplicates() uses the duplicate rules associated with the Account object.
For each input sObject, findDuplicates() adds a FindDuplicatesResult object to the output array.
All the sObject elements in the input array must have the same type, and that type must correspond to an object type that supports duplicate rules.
The input array is limited to 50 elements. If you exceed this limit, the SOAP call returns an API Fault Element containing these fields.
exceptionMessage: Configuration error: The number of records to check is greater than the permitted batch size.
Note
The values specified in the sObject control matching. The values can include a record ID, a field map, or both. The specified values determine the behavior of findDuplicates():
Record ID only
findDuplicates() searches the object defined by the duplicate rule for an existing record that has the same ID. Then it loads the values from that record, and searches for duplicates based on those values.
Field Map only:findDuplicates() loads the values from the map and searches for duplicates based on those values.
Record ID and Field Map
findDuplicates() searches the object defined by the duplicate rule for an existing record that has the same ID. It loads any values from that record that aren’t specified in the map, and then loads values from the map. Based on the resulting union of values, findDuplicates() searches for duplicates.
The output of findDuplicates() is an array of FindDuplicatesResult objects with the same number of elements as the input array, and in the same order. The output objects encapsulate record IDs for duplicate records, if any. Optionally, the output objects also contain values from the duplicate records.
Each FindDuplicatesResult element contains a DuplicateResult object. If findDuplicates() doesn’t find any duplicates for an sObject, the duplicateRule field in DuplicateResult contains the name of the duplicate rule that findDuplicates() applied, but the matchResults array is empty.
If the includeRecordDetails flag in DuplicateRuleHeader is set to false, findDuplicates() only returns the record IDs of the matching records. Otherwise, findDuplicates() returns all the fields specified in the primary CompactLayout associated with the target object.
Basic Steps for Use
Create one or more sObject objects with a type that corresponds to the object that has the duplicate rules you want to use.
In each sObject, specify record IDs or field maps (or both) to compare to records in the object.
The following Java sample demonstrates how to search for duplicates of a Lead, using the standard Leads duplicate rule.
1package wsc;23import com.sforce.soap.partner.*;4import com.sforce.soap.partner.Error;5import com.sforce.soap.partner.sobject.SObject;6import com.sforce.ws.ConnectionException;7import com.sforce.ws.ConnectorConfig;89public class Main {1011 private static final String USERNAME = "YOUR-USERNAME";12 private static final String PASSWORD = "YOUR-PASSWORD&SECURITY-TOKEN";13 private static PartnerConnection connection = null;1415 public static void main(String[] args) throws ConnectionException {1617 // Create the configuration for the partner connection18 ConnectorConfig config = new ConnectorConfig();19 config.setUsername(USERNAME);20 config.setPassword(PASSWORD);2122 // Initialize the connection23 connection = new PartnerConnection(config);2425 SObject[] inputSObjectArray = new SObject[1];26 // Instantiate an empty Java SObject27 SObject searchCriteria = new SObject();28 // Set its type to Lead. This tells findDuplicates() to use the duplicate rules29 // for Lead30 searchCriteria.setType("Lead");31 /*32 * Set the necessary fields for matching, based on the standard matching rules for Lead (Search33 * help.salesforce.com for "Standard Contact and Lead Matching Rule" to see the rules).34 */35 searchCriteria.setField("FirstName", "Marc");36 searchCriteria.setField("LastName", "Benioff");37 searchCriteria.setField("Company", "Salesforce.com Inc");38 searchCriteria.setField("Title", "CEO");39 searchCriteria.setField("Email", "ceo@salesforce.com");40 // Add the sObject to the input array41 inputSObjectArray[0] = searchCriteria;42 /*43 * By default, findDuplicates() returns only record IDs. To return additional values, set the second parameter44 * to true.45 */46 connection.setDuplicateRuleHeader(47 /*48 * @param allowSave - Not Applicable for this API call49 */50 false,51 /* @param includeRecordDetails */52 false,53 /*54 * @param runAsCurrentUser - Not Applicable for this API call55 */56 false);5758 // Invoke findDuplicates() to find duplicates based on the information in the59 // SObject array60 FindDuplicatesResult[] callResults = connection.findDuplicates(inputSObjectArray);6162 // Iterate through the results63 // For each SObject in the input array, get the duplicate results64 for (FindDuplicatesResult findDupeResult : callResults) {65 // If errors were found for this SObject, print them out66 if (!findDupeResult.isSuccess()) {67 for (Error findDupError : findDupeResult.getErrors()) {68 System.out.println("FindDuplicatesRule errors detected: " + findDupError.getMessage());69 }70 } else {71 /*72 * Get the DuplicateResult object array for the result. Each element in the array represents the result73 * of testing one duplicate rule for the SObject. Process each DuplicateResult.74 */75 for (DuplicateResult dupeResult : findDupeResult.getDuplicateResults()) {76 System.out.println("Duplicate rule: " + dupeResult.getDuplicateRule());77 // Print out the name of the object associated with the duplicate78 // rule79 System.out.println("Source of this duplicate rule is: " + dupeResult.getDuplicateRuleEntityType());80 for (MatchResult matchResult : dupeResult.getMatchResults()) {81 if (!matchResult.isSuccess()) {82 for (Error e : matchResult.getErrors()) {83 System.out.println("Errors detected: " + e.getMessage());84 }85 } else {86 System.out.println("Matching rule is: " + matchResult.getRule());87 System.out.println("Object type for this matching rule is: " + matchResult.getEntityType());88 for (MatchRecord matchRecord : matchResult.getMatchRecords()) {89 System.out.println("Duplicate record ID: " + matchRecord.getRecord().getId());90 }91 }92 }93 }94 }95 }96 }97}
Arguments
Name
Type
Description
sObjects
Array of sObject
Required. A list of sObject objects that contain values you want to search for.
Response
An array of FindDuplicatesResult objects.
FindDuplicatesResult
Represents the result of a duplicate search for a single sObject in the input array. Because the object associated with the sObject can have more than one duplicate rule, FindDuplicatesResult contains an array of DuplicateResult objects.
Fields
duplicateResults
Type: Array of DuplicateResult objects
Description: The result of each duplicate rule applied by findDuplicates() to a single sObject.
errors
Type: Array of Error objects
Description: Contains an array of errors encountered by findDuplicates().
success
Type: boolean
Description: This field is set to true if the findDuplicates() doesn’t encounter any errors.