Represents the details of a duplicate rule that detected duplicate records and information about those duplicate records.
Fields
allowSave
Type: boolean
Description:true if duplicates are allowed to be saved. false if duplicates are not allowed to be saved.
duplicateRule
Type: string
Description: The name of the duplicate rule that detected duplicate records.
duplicateRuleEntityType
Type: string
Description: The name of the duplicate rule that detected duplicate records.
errorMessage
Type: string
Description: The error message configured by the administrator to warn users they are potentially creating duplicate records. This message is associated with a duplicate rule.
Description: The duplicate records and related match information.
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;23import java.io.FileNotFoundException;45import 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;1011public class SaveResultsWithDupeHeader {1213 private PartnerConnection partnerConnection = null;14 static SaveResultsWithDupeHeader tester;1516 public static void main(String[] args) {17 tester = new SaveResultsWithDupeHeader();18 try {19 tester.demoDuplicateRuleHeader();20 } catch (Exception e) {21 e.printStackTrace();22 }23 }2425 /*26 * Make sure that you have an active lead duplicate rule linked to an active matching rule. This method tries to save27 * an array of leads and inspects whether any duplicates were detected28 */29 public void demoDuplicateRuleHeader() throws FileNotFoundException, ConnectionException {30 // Create the configuration for the partner connection31 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);3839 // Initialize the connection40 partnerConnection = new PartnerConnection(config);4142 // Get the leads that have to be saved43 SObject[] leads = getLeadsForInsertOrUpdate();4445 /* Set a duplicate rule header to return a result if duplicates are detected46 * This sets the allowSave, includeRecordDetails, and runAsCurrentUser flags to true47 */48 partnerConnection.setDuplicateRuleHeader(true, true, true);4950 // Save the leads51 SaveResult[] saveResults = partnerConnection.create(leads);5253 // Check the results to see if duplicates were detected54 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 DuplicateError59 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 }8384 // Clear the duplicate rule header85 partnerConnection.clearDuplicateRuleHeader();86 }8788 /**89 * The assumption here is that this method is retrieving leads from either UI, a data source, etc90 */91 private SObject[] getLeadsForInsertOrUpdate() {92 return new SObject[0];93 }9495}