Newer Version Available
DuplicateResult
Represents the details of a duplicate rule that detected duplicate
records and information about those duplicate records.
Fields
| Field | Details |
|---|---|
| allowSave |
|
| duplicateRule |
|
| duplicateRuleEntityType |
|
| errorMessage |
|
| matchResults |
|
Usage
DuplicateResult and its constituent objects are available to organizations that use duplicate rules.
Java Sample
Here is a sample that shows how to block users from entering duplicate leads and display an alert and a list of duplicates.
1package com.doc.example;
2
3import java.io.FileNotFoundException;
4
5import com.sforce.soap.partner.*;
6import com.sforce.soap.partner.Error;
7import com.sforce.soap.partner.sobject.SObject;
8import com.sforce.ws.ConnectionException;
9import com.sforce.ws.ConnectorConfig;
10
11public class SaveResultsWithDupeHeader {
12
13 private PartnerConnection partnerConnection = null;
14 static SaveResultsWithDupeHeader tester;
15
16 public static void main(String[] args) {
17 tester = new SaveResultsWithDupeHeader();
18 try {
19 tester.demoDuplicateRuleHeader();
20 } catch (Exception e) {
21 e.printStackTrace();
22 }
23 }
24
25 /*
26 * Make sure that you have an active lead duplicate rule linked to an active matching rule. This method tries to save
27 * an array of leads and inspects whether any duplicates were detected
28 */
29 public void demoDuplicateRuleHeader() throws FileNotFoundException, ConnectionException {
30 // Create the configuration for the partner connection
31 ConnectorConfig config = new ConnectorConfig();
32 config.setUsername("user@domain.com");
33 config.setPassword("secret");
34 config.setAuthEndpoint("authEndPoint");
35 config.setTraceFile("traceLogs.txt");
36 config.setTraceMessage(true);
37 config.setPrettyPrintXml(true);
38
39 // Initialize the connection
40 partnerConnection = new PartnerConnection(config);
41
42 // Get the leads that have to be saved
43 SObject[] leads = getLeadsForInsertOrUpdate();
44
45 /* Set a duplicate rule header to return a result if duplicates are detected
46 * This sets the allowSave, includeRecordDetails, and runAsCurrentUser flags to true
47 */
48 partnerConnection.setDuplicateRuleHeader(true, true, true);
49
50 // Save the leads
51 SaveResult[] saveResults = partnerConnection.create(leads);
52
53 // Check the results to see if duplicates were detected
54 for (int i = 0; i < leads.length; i++) {
55 SaveResult saveResult = saveResults[i];
56 if (!saveResult.isSuccess()) {
57 for (Error e : saveResult.getErrors()) {
58 // See if there are any errors on the saveResult with a data type of DuplicateError
59 if (e instanceof DuplicateError) {
60 System.out.println("Duplicate(s) Detected for lead with ID: " + leads[i].getId());
61 System.out.println("ERROR MESSAGE: " + e.getMessage());
62 System.out.println("STATUS CODE: " + e.getStatusCode());
63 DuplicateResult dupeResult = ((DuplicateError)e).getDuplicateResult();
64 System.out.println("Found the following duplicates...");
65 for (MatchResult m : dupeResult.getMatchResults()) {
66 if (m.isSuccess()) {
67 System.out.println("The match rule that was triggered was " + m.getRule());
68 for (MatchRecord mr : m.getMatchRecords()) {
69 System.out.println("Your record matched " + mr.getRecord().getId() + " of type "
70 + mr.getRecord().getType());
71 System.out.println("The match confidence is " + mr.getMatchConfidence());
72 for (FieldDiff f : mr.getFieldDiffs()) {
73 System.out.println("For field " + f.getName() + " field difference is "
74 + f.getDifference().name());
75 }
76 }
77 }
78 }
79 }
80 }
81 }
82 }
83
84 // Clear the duplicate rule header
85 partnerConnection.clearDuplicateRuleHeader();
86 }
87
88 /**
89 * The assumption here is that this method is retrieving leads from either UI, a data source, etc
90 */
91 private SObject[] getLeadsForInsertOrUpdate() {
92 return new SObject[0];
93 }
94
95}