この文章は Salesforce 機械翻訳システムを使用して翻訳されました。詳細はこちらをご参照ください。
英語に切り替える

DuplicateResult

重複レコードを検出した重複ルールの詳細と、それらの重複レコードに関する情報を表します。

項目

項目 詳細
allowSave
boolean
説明
重複を保存できる場合は true。重複を保存できない場合は false
duplicateRule
string
説明
重複レコードを検出した重複ルールの名前。
duplicateRuleEntityType
string
説明
重複レコードを検出した重複ルールの名前。
errorMessage
string
説明
重複レコードを作成している可能性があることをユーザに警告するために、システム管理者が設定したエラーメッセージ。このメッセージは重複ルールに関連付けられています。
matchResults
MatchResult
説明
重複レコードおよび関連する一致情報。

使用方法

重複ルールを使用する組織は、DuplicateResult とその構成要素オブジェクトを使用できます。

Java のサンプル

重複するリードのユーザによる入力をブロックし、アラートと重複のリストを表示する方法の例を次に示します。

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}