Newer Version Available

This content describes an older version of this product. View Latest

DuplicateError

Contains information about an error that occurred when an attempt was made to save a duplicate record. Use if your organization has set up duplicate rules, which are part of the Duplicate Management feature.

Fields

Field Details
duplicateResult
Type
DuplicateResult
Description
The details of a duplicate rule and duplicate records found by the duplicate rule.
fields
Type
string[]
Description
Array of one or more field names. Identifies which fields in the object, if any, affected the error condition.
message
Type
string
Description
Error message text.
statusCode
Type
StatusCode
Description
A code that characterizes the error. The full list of status codes is available in the WSDL file for your organization (see Generating the WSDL File for Your Organization).

Usage

DuplicateError and its constituent objects are available to organizations that use duplicate rules.

DuplicateError is a data type of Error.

To process duplicates, loop through all the Error objects in the errors field on SaveResult. An Error object with a data type of DuplicateError contains information about an error that occurred when an attempt was made to save a duplicate record. To access information about the duplicates, use the duplicateResult field.

Java Sample

Here’s a sample that shows how to see if there are any errors on the saveResult with a data type of DuplicateError. If so, duplicates were detected. See DuplicateResult for a full code sample that shows how to block users from entering duplicate leads and display an alert and a list of duplicates.

1if (!saveResult.isSuccess()) {
2    for (Error e : saveResult.getErrors()) {
3        if (e instanceof DuplicateError) {
4            System.out.println("Duplicate(s) Detected for lead with ID: " + leads[i].getId());
5            System.out.println("ERROR MESSAGE: " + e.getMessage());
6            System.out.println("STATUS CODE: " + e.getStatusCode());
7            DuplicateResult dupeResult = ((DuplicateError)e).getDuplicateResult();
8            System.out.println("Found the following duplicates...");
9            for (MatchResult m : dupeResult.getMatchResults()) {
10                if (m.isSuccess()) {
11                    System.out.println("The match rule that was triggered was " + m.getRule());
12                    for (MatchRecord mr : m.getMatchRecords()) {
13                        System.out.println("Your record matched " + mr.getRecord().getId() + " of type "
14                            + mr.getRecord().getType());
15                        System.out.println("The match confidence is " + mr.getMatchConfidence());
16                    }
17                }
18            }
19        }
20    }
21}