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

findDuplicates()

ルールに基づいて、重複レコードの検索を実行します。

入力は sObject の配列で、それぞれが検索する値と重複ルールを示すオブジェクトの種別を指定します。重複ルールを示すオブジェクトごとに、検出された重複が出力で識別されます。findDuplicates() はルールを値に適用し、検索を実行します。sObject ごとに、検出された重複が出力で識別されます。

構文

1FindDuplicatesResult[] duplicateResults = 
2    connection.findDuplicates(SObject[] inputSObjectArray);

使用方法

オブジェクトに関連付けられた重複ルールを各 sObject で指定された値に適用するには、findDuplicates() を使用します。各 sObject には、オブジェクトに対応する種別もあります。

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

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

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

メモ

sObject コントロール一致で指定された値。値にはレコード ID、項目の対応付け、またはその両方が含まれる可能性があります。指定された値によって、findDuplicates() の動作が決まります。

レコード ID のみ
findDuplicates() は、重複ルールで定義されたオブジェクトで同じ ID を持つ既存のレコードを検索します。次に、そのレコードから値を読み込み、それらの値に基づいて重複があるか検索します。
項目の対応付けのみ
findDuplicates() は、対応付けから値を読み込み、それらの値に基づいて重複があるか検索します。
レコード ID と項目の対応付け
findDuplicates() は、重複ルールで定義されたオブジェクトで同じ ID を持つ既存のレコードを検索します。対応付けで指定されていないレコードから値を読み込み、次に対応付けから値を読み込みます。値の結合結果に基づいて、findDuplicates() は重複があるか検索します。

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

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

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

基本的な使用手順

  1. 使用する重複ルールを持つオブジェクトに対応する種別の sObject オブジェクトを 1 つ以上作成します。
  2. 各 sObject で、レコード 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[] inputSObjectArray = new SObject[1];
26    // Instantiate an empty Java SObject
27    SObject searchCriteria = new SObject();
28    // Set its type to Lead. This tells findDuplicates() to use the duplicate rules
29    // for Lead
30    searchCriteria.setType("Lead");
31    /*
32     * Set the necessary fields for matching, based on the standard matching rules for Lead (Search
33     * help.salesforce.com for "Standard Contact and Lead Matching Rule" to see the rules).
34     */
35    searchCriteria.setField("FirstName", "Marc");
36    searchCriteria.setField("LastName", "Benioff");
37    searchCriteria.setField("Company", "Salesforce.com Inc");
38    searchCriteria.setField("Title", "CEO");
39    searchCriteria.setField("Email", "ceo@salesforce.com");
40    // Add the sObject to the input array
41    inputSObjectArray[0] = searchCriteria;
42    /*
43     * By default, findDuplicates() returns only record IDs. To return additional values, set the second parameter
44     * to true.
45     */
46    connection.setDuplicateRuleHeader(
47        /*
48         * @param allowSave - Not Applicable for this API call
49         */
50        false,
51        /* @param includeRecordDetails */
52        false,
53        /*
54         * @param runAsCurrentUser - Not Applicable for this API call
55         */
56        false);
57
58    // Invoke findDuplicates() to find duplicates based on the information in the
59    // SObject array
60    FindDuplicatesResult[] callResults = connection.findDuplicates(inputSObjectArray);
61
62    // Iterate through the results
63    // For each SObject in the input array, get the duplicate results
64    for (FindDuplicatesResult findDupeResult : callResults) {
65      // If errors were found for this SObject, print them out
66      if (!findDupeResult.isSuccess()) {
67        for (Error findDupError : findDupeResult.getErrors()) {
68          System.out.println("FindDuplicatesRule errors detected: " + findDupError.getMessage());
69        }
70      } else {
71        /*
72         * Get the DuplicateResult object array for the result. Each element in the array represents the result
73         * of testing one duplicate rule for the SObject. Process each DuplicateResult.
74         */
75        for (DuplicateResult dupeResult : findDupeResult.getDuplicateResults()) {
76          System.out.println("Duplicate rule: " + dupeResult.getDuplicateRule());
77          // Print out the name of the object associated with the duplicate
78          // rule
79          System.out.println("Source of this duplicate rule is: " + dupeResult.getDuplicateRuleEntityType());
80          for (MatchResult matchResult : dupeResult.getMatchResults()) {
81            if (!matchResult.isSuccess()) {
82              for (Error e : matchResult.getErrors()) {
83                System.out.println("Errors detected: " + e.getMessage());
84              }
85            } else {
86              System.out.println("Matching rule is: " + matchResult.getRule());
87              System.out.println("Object type for this matching rule is: " + matchResult.getEntityType());
88              for (MatchRecord matchRecord : matchResult.getMatchRecords()) {
89                System.out.println("Duplicate record ID: " + matchRecord.getRecord().getId());
90              }
91            }
92          }
93        }
94      }
95    }
96  }
97}

引数

名前 説明
sObjects sObject の配列 必須。検索する値が含まれる sObject オブジェクトのリスト。

応答

FindDuplicatesResult オブジェクトの配列。

FindDuplicatesResult

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

項目

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