findDuplicatesByIds() performs rule-based searches for duplicate records. The input is an array of record IDs, each of which specifies what records to search for duplicates. The output identifies the detected duplicates for each record ID.
Use findDuplicatesByIds() to apply duplicate rules associated with an object to records represented by the record IDs.
findDuplicatesByIds() uses the duplicate rules for the object that has the same type as the input record IDs. For example, if the record ID represents an Account, findDuplicatesByIds() uses the duplicate rules associated with the Account object.
For each input ID, findDuplicatesByIds() adds an object to the output array.
All record IDs in the input array must have the same object 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 contains these fields.
exceptionMessage: Configuration error: The number of records to check is greater than the permitted batch size.
Note
Matching is controlled by the values specified by the input record ID. The values can include a record ID only.
findDuplicatesByIds() 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.
The output of findDuplicatesByIds() is an array of 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. Optionally, the output objects also contain values from the duplicate records.
Each element contains a DuplicateResult object. If findDuplicatesByIds() doesn’t find any duplicates for an sObject, the duplicateRule field in DuplicateResult contains the name of the duplicate rule that findDuplicatesByIds() applied, but the matchResults array is empty.
If the includeRecordDetails flag in DuplicateRuleHeader is set to false, findDuplicatesByIds() returns only the record IDs of the matching records. Otherwise, findDuplicatesByIds() returns all the fields specified in the primary CompactLayout associated with the target object.
Basic Steps for Using findDuplicatesByIds()
Create one or more ID objects that correspond to the object that has the duplicate rules you want to use.
Specify record IDs to compare to records in the object.
Set DuplicateRuleHeader to control the output you want.
Sample
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[] objectsToSearch = new SObject[2];26 String[] inputIds = new String[2];27 // Instantiate an empty Java SObject28 SObject searchCriteria = new SObject();29 // Set its type to Lead. This tells findDuplicatesByIds() to use the duplicate rules30 // for Lead31 searchCriteria.setType("Lead");32 /*33 * Set the necessary fields for matching, based on the standard matching rules for Lead34 * (Search help.salesforce.com for "Standard Contact and Lead Matching Rule" to see the35 * rules).36 */37 searchCriteria.setField("FirstName", "Marc");38 searchCriteria.setField("LastName", "Benioff");39 searchCriteria.setField("Company", "Salesforce.com Inc");40 searchCriteria.setField("Title", "CEO");41 searchCriteria.setField("Email", "ceo@salesforce.com");42 // Add the sObjects to the input array43 objectsToSearch[0] = searchCriteria;44 objectsToSearch[1] = searchCriteria;4546 SaveResult[] saveResults = connection.create(objectsToSearch);4748 for (int i = 0; i < saveResults.length; ++i) {49 if (saveResults[i].isSuccess()) {50 System.out.println("Successfully created ID: " + saveResults[i].getId());51 inputIds[i] = saveResults[i].getId();52 } else {53 System.out.println("Error: could not create SObject.");54 System.out.println("The error reported was: " +55 saveResults[i].getErrors()[0].getMessage() + "\n");56 }57 }58 /*59 * By default, findDuplicatesByIds() returns only record IDs. To return additional values,60 * set the second parameter to true.61 */62 connection.setDuplicateRuleHeader(63 /*64 * @param allowSave - Not Applicable for this API call65 */66 false,67 /* @param includeRecordDetails */68 false,69 /*70 * @param runAsCurrentUser - Not Applicable for this API call71 */72 false);7374 // Invoke findDuplicatesByIds() to find duplicates based on the information in the75 // SObject array76 FindDuplicatesResult[] callResults = connection.findDuplicatesByIds(inputIds);7778 // Iterate through the results79 /* For each Id in the input array, get the duplicate results. There could be more matches80 * depending on the data in the organization.81 */82 for (FindDuplicatesResult findDupeResult : callResults) {83 // If errors were found for this Id, print them out84 if (!findDupeResult.isSuccess()) {85 for (Error findDupError : findDupeResult.getErrors()) {86 System.out.println("FindDuplicatesRule errors detected: " + findDupError.getMessage());87 }88 } else {89 /*90 * Get the DuplicateResult object array for the result. Each element in the array represents91 * the result of testing one duplicate rule for the Id. Process each DuplicateResult.92 */93 for (DuplicateResult dupeResult : findDupeResult.getDuplicateResults()) {94 System.out.println("Duplicate rule: " + dupeResult.getDuplicateRule());95 // Print out the name of the object associated with the duplicate96 // rule97 System.out.println("Source of this duplicate rule is: " +98 dupeResult.getDuplicateRuleEntityType());99 for (MatchResult matchResult : dupeResult.getMatchResults()) {100 if (!matchResult.isSuccess()) {101 for (Error e : matchResult.getErrors()) {102 System.out.println("Errors detected: " + e.getMessage());103 }104 } else {105 System.out.println("Matching rule is: " + matchResult.getRule());106 System.out.println("Object type for this matching rule is: " + matchResult.getEntityType());107 for (MatchRecord matchRecord : matchResult.getMatchRecords()) {108 System.out.println("Duplicate record ID: " + matchRecord.getRecord().getId());109 }110 }111 }112 }113 }114 }115 }116}
Arguments
Name
Type
Description
IDs
Array of ID
Required. A list of IDs 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 ID 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 findDuplicatesByIds() to a single sObject.