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

findDuplicatesByIds()

ルールに基づいて、重複レコードの検索を実行します。入力は ID の配列で、各要素は重複を検索するレコードを指定します。重複ルールを示すオブジェクトごとに、検出された重複が出力で識別されます。findDuplicatesByIds() はルールをレコード ID に適用し、検索を実行します。ID ごとに、検出された重複が出力で識別されます。

構文

1FindDuplicatesResult[] duplicateResults = 
2    connection.findDuplicatesByIds(Id[] inputIdArray);

使用方法

オブジェクトに関連付けられた重複ルールを、レコード ID で表されたレコードに適用するには、findDuplicatesByIds() を使用します。

findDuplicatesByIds() は、入力レコード ID と同じ種別のオブジェクトの重複ルールを使用します。たとえば、レコード ID が取引先を表す場合、findDuplicatesByIds() は Account オブジェクトに関連付けられた重複ルールを使用します。

  • 入力配列内のすべてのレコード ID は同じオブジェクト種別である必要があり、その種別は重複ルールをサポートするオブジェクト種別に対応す���必要があります。
  • 入力配列は 50 要素までに制限されます。この制限を超えた場合、SOAP コールは次の項目を含む API 障害要素を返します。
  • ExceptionCode: LIMIT_EXCEEDED
  • exceptionMessage: Configuration error: The number of records to check is greater than the permitted batch size.

メモ

入力 ID ごとに、findDuplicatesByIds() はオブジェクトを出力配列に追加します。

照合は、入力レコード ID で指定された値によって制御されます。値にはレコード ID のみを含めることができます。

findDuplicatesByIds() は、重複ルールで定義されたオブジェクトで同じ ID を持つ既存のレコードを検索します。次に、そのレコードから値を読み込み、それらの値に基づいて重複があるか検索します。

findDuplicatesByIds() の出力は、入力配列と同じ要素数と順序のオブジェクトの配列です。出力オブジェクトでは、重複レコードのレコード ID がカプセル化されます。必要に応じて、出力オブジェクトには重複レコードからの値も含まれます。

各要素に DuplicateResult オブジェクトが含まれます。findDuplicatesByIds() で sObject の重複が検出されなかった場合、DuplicateResult の duplicateRule 項目には、findDuplicatesByIds() が適用した重複ルールの名前が含まれますが、matchResults 配列は空です。

DuplicateRuleHeaderincludeRecordDetails フラグが false に設定されている場合、findDuplicatesByIds() は一致するレコードのレコード ID のみを返します。それ以外の場合、findDuplicatesByIds() は対象オブジェクトに関連付けられているプライマリ CompactLayout で指定されたすべての項目を返します。

基本的な使用手順

  1. 使用する重複ルールを持つオブジェクトに対応する ID オブジェクトを 1 つ以上作成します。
  2. レコード ID を指定して、オブジェクトのレコードと比較します。
  3. 必要な出力を制御するために、DuplicateRuleHeader を設定します。

サンプル

次の Java サンプルは、標準のリード重複ルールを使用してリードの重複を検索する方法を示します。

1package wsc;
2
3import com.sforce.soap.partner.*;
4import com.sforce.soap.partner.Error;
5import com.sforce.soap.partner.sobject.SObject;
6import com.sforce.ws.ConnectionException;
7import com.sforce.ws.ConnectorConfig;
8
9public class Main {
10
11  private static final String USERNAME = "YOUR-USERNAME";
12  private static final String PASSWORD = "YOUR-PASSWORD&SECURITY-TOKEN";
13  private static PartnerConnection connection = null;
14
15  public static void main(String[] args) throws ConnectionException {
16
17    // Create the configuration for the partner connection
18    ConnectorConfig config = new ConnectorConfig();
19    config.setUsername(USERNAME);
20    config.setPassword(PASSWORD);
21
22    // Initialize the connection
23    connection = new PartnerConnection(config);
24
25    SObject[] objectsToSearch = new SObject[2];
26    String[] inputIds = new String[2];
27    // Instantiate an empty Java SObject
28    SObject searchCriteria = new SObject();
29    // Set its type to Lead. This tells findDuplicatesByIds() to use the duplicate rules
30    // for Lead
31    searchCriteria.setType("Lead");
32    /*
33     * Set the necessary fields for matching, based on the standard matching rules for Lead
34     * (Search help.salesforce.com for "Standard Contact and Lead Matching Rule" to see the
35     * rules).
36     */
37    searchCriteria.setField("FirstName", "Marc");
38    searchCriteria.setField("LastName", "Benioff");
39    searchCriteria.setField("Company", "Salesforce.com Inc");
40    searchCriteria.setField("Title", "CEO");
41    searchCriteria.setField("Email", "ceo@salesforce.com");
42    // Add the sObjects to the input array
43    objectsToSearch[0] = searchCriteria;
44    objectsToSearch[1] = searchCriteria;
45
46    SaveResult[] saveResults = connection.create(objectsToSearch);
47
48    for (int i = 0; i < saveResults.length; ++i) {
49      if (saveResults[i].isSuccess()) {
50        System.out.println("Successfully created ID: " + saveResults[i].getId());
51        inputIds[i] = saveResults[i].getId();
52      } else {
53        System.out.println("Error: could not create SObject.");
54        System.out.println("The error reported was: " + 
55          saveResults[i].getErrors()[0].getMessage() + "\n");
56      }
57    }
58    /*
59     * By default, findDuplicatesByIds() returns only record IDs. To return additional values,
60     * set the second parameter to true.
61     */
62    connection.setDuplicateRuleHeader(
63        /*
64         * @param allowSave - Not Applicable for this API call
65         */
66        false,
67        /* @param includeRecordDetails */
68        false,
69        /*
70         * @param runAsCurrentUser - Not Applicable for this API call
71         */
72        false);
73
74    // Invoke findDuplicatesByIds() to find duplicates based on the information in the
75    // SObject array
76    FindDuplicatesResult[] callResults = connection.findDuplicatesByIds(inputIds);
77
78    // Iterate through the results
79    /* For each Id in the input array, get the duplicate results. There could be more matches
80     * depending on the data in the organization.
81     */
82    for (FindDuplicatesResult findDupeResult : callResults) {
83      // If errors were found for this Id, print them out
84      if (!findDupeResult.isSuccess()) {
85        for (Error findDupError : findDupeResult.getErrors()) {
86          System.out.println("FindDuplicatesRule errors detected: " + findDupError.getMessage());
87        }
88      } else {
89        /*
90         * Get the DuplicateResult object array for the result. Each element in the array represents
91         * the result of testing one duplicate rule for the Id. Process each DuplicateResult.
92         */
93        for (DuplicateResult dupeResult : findDupeResult.getDuplicateResults()) {
94          System.out.println("Duplicate rule: " + dupeResult.getDuplicateRule());
95          // Print out the name of the object associated with the duplicate
96          // rule
97          System.out.println("Source of this duplicate rule is: " + 
98            dupeResult.getDuplicateRuleEntityType());
99          for (MatchResult matchResult : dupeResult.getMatchResults()) {
100            if (!matchResult.isSuccess()) {
101              for (Error e : matchResult.getErrors()) {
102                System.out.println("Errors detected: " + e.getMessage());
103              }
104            } else {
105              System.out.println("Matching rule is: " + matchResult.getRule());
106              System.out.println("Object type for this matching rule is: " + matchResult.getEntityType());
107              for (MatchRecord matchRecord : matchResult.getMatchRecords()) {
108                System.out.println("Duplicate record ID: " + matchRecord.getRecord().getId());
109              }
110            }
111          }
112        }
113      }
114    }
115  }
116}

引数

名前 種別 説明
IDs ID の配列 必須。検索する値が含まれる ID のリスト。

返答

FindDuplicatesResult オブジェクトの配列。

FindDuplicatesResult

入力配列内の 1 つの ID の重複検索の結果を表します。sObject に関連付けられたオブジェクトには複数の重複ルールを設定できるため、FindDuplicatesResult には DuplicateResult オブジェクトの配列が含まれます。

項目

項目名 項目の型 説明
duplicateResults DuplicateResult オブジェクトの配列 findDuplicatesByIds() によって 1 つの sObject に適用された各重複ルールの結果。
errors Error オブジェクトの配列 findDuplicatesByIds() で発生したエラーの配列が含まれます。
success boolean findDuplicatesByIds() でエラーが発生しなかった場合、この項目は true に設定されます。