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