FindDuplicatesByIds Class
Namespace
FindDuplicatesByIds Methods
The following are methods for FindDuplicatesByIds.
findDuplicatesByIds(ids)
Usage
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.
FindDuplicatesByIds identifies duplicate records according to activated standard and custom matching rules. Standard matching rules don’t include custom fields in their matching criteria. You can configure custom matching rules that do include custom fields for matching criteria, and then assign the custom matching rule to a duplicate rule. However, configuring these rules isn’t a part of the Datacloud API.
- Input
-
- All record IDs in the input array must be of 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, an exception is thrown with the following message: Configuration error: The number of records to check is greater than the permitted batch size.
- Output
-
- 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. The output objects also contain values from the duplicate records.
- Each element contains an array of DuplicateResult objects, which each represent a duplicate rule that FindDuplicatesByIds applied. Within each DuplicateResult object is an array of MatchResult objects, which each represent a matching rule that the duplicate rule applied. If FindDuplicatesByIds doesn’t find any duplicates for that matching rule, then the MatchResult.getMatchRecords() array is empty. Otherwise, the MatchResult.getMatchRecords() array contains MatchRecord objects, which each represent a duplicate record.
- If no duplicate rule is active for the object type of the record IDs in the input array, a System.HandledException exception is thrown with this message: No active duplicate rules are defined for the {ObjectName} object type.
Example
1// Create list of existing record IDs to check for duplicates
2List<Id> idList = new List<Id>();
3idList.add('EXISTING_ID'); // Replace placeholder with an existing 18-digit record ID
4
5// Call the FindDuplicatesByIds method, which returns one FindDuplicatesResult for each ID in the input list.
6List<Datacloud.FindDuplicatesResult> results = Datacloud.FindDuplicatesByIds.findDuplicatesByIds(idList);
7
8//Get the result for the first record ID (index 0).
9Datacloud.FindDuplicatesResult idResult = results[0];
10
11// Check that findDuplicates() was successfully executed for this record
12if (!idResult.isSuccess()) {
13 List<Database.Error> errs = idResult.getErrors();
14 for (Database.Error err : errs) {
15 System.debug(err.getMessage());
16 }
17} else {
18
19 Boolean duplicatesFound = false;
20 Boolean matchError = false;
21
22 // Iterate through the duplicate rules that were evaluated.
23 for (Datacloud.DuplicateResult dupResult : idResult.getDuplicateResults()) {
24 // Iterate through the matching rules that were evaluated for each duplicate rule
25 for (Datacloud.MatchResult matchResult : dupResult.getMatchResults()) {
26 // Check that getMatchResults() was successfully executed for this matching rule
27 if (!matchResult.isSuccess()) {
28 List<Database.Error> errs = matchResult.getErrors();
29 for (Database.Error err : errs) {
30 System.debug(err.getMessage());
31 }
32 matchError = true;
33 } else {
34 // Check if duplicates are found according to the matching rule
35 if (!matchResult.getMatchRecords().isEmpty()) {
36 System.debug('Duplicate record(s) found with matching rule: ' + matchResult.getRule());
37 duplicatesFound = true;
38 // Get information about the duplicates
39 for (Datacloud.MatchRecord matchRecord : matchResult.getMatchRecords()) {
40 System.debug('Duplicate record: ' + matchRecord.getRecord());
41 }
42 }
43 }
44 }
45 }
46
47 // If no duplicates were found and no errors occurred for first record ID
48 if (!duplicatesFound && !matchError) {
49 System.debug('No duplicates found for record ID: ' + idList[0]);
50 }
51}Signature
public static List<Datacloud.FindDuplicatesResult> findDuplicatesByIds(List<Id> ids)
Return Value
Type: List<FindDuplicatesResult>