* C. Update the PrimaryId__c field definition to mark it as an External Id: * Marking PrimaryId__c as an External Id allows Salesforce to use this field to match records during the data import process, streamlining the process of mapping CSV rows to existing Candidate__c records. * External Id fields are indexed and can be used in tools like Data Loader, Data Import Wizard, or API-based upserts to ensure that records are matched correctly based on the value of the external ID field. * In this case, since PrimaryId__c is unique, marking it as an external ID eliminates the need for custom triggers or flows. * Why this is the best solution? * This technique leverages built-in Salesforce capabilities (no need for custom code or automation). * It ensures accurate record matching and is the standard approach for data enrichment tasks involving unique identifiers. Why not the other options? * A. Upload the CSV into a custom object related to Candidate__c: * This approach unnecessarily introduces another object, adding complexity. The goal is to update existing Candidate__c records, not store the data in a separate object. * B. Create a before insert trigger to correctly map the records: * Using triggers for this purpose is overengineering. Salesforce already provides tools like upsert for this exact use case. Writing a trigger would require additional effort and could introduce unintended errors or performance issues. * D. Create a before save flow to correctly map the records: * While flows are powerful, they are not the optimal solution for this use case. Data mapping is better handled using an external ID during import to ensure proper matching and updates. References: * External IDs in Salesforce * Upsert with Data Loader * Unique and External ID Fields
最新のコメント (最新のコメントはトップにあります。)
【完全版解説】CSVインポートと外部IDのマッピング問題の概要シナリオ: Candidate__c オブジェクトに、CSVファイルを使って大量のデータをアップロードしたい。要件: CSV内の PrimaryId__c(各候補者の固有ID)を使って、Salesforce内の既存レコードと紐付け(マッピング)を行いたい。ゴール: データのアップロードを効率化する。出題領域領域: 1. 開発者の基本 (Developer Fundamentals)トピック: データのインポート/エクスポート、データモデリング、外部ID正解:CC. PrimaryId__c フィールド定義を更新して、外部 ID (External ID) としてマークします。解説:なぜこれが正解なのか?Salesforceへのデータロードにおいて、最も効率的な手法は**「標準機能」**を最大限に活用することです。外部ID (External ID) の役割:SalesforceのレコードID(001...)の代わりに、他システムやCSV上のユニークなID(社員番号、会員IDなど)をレコードの識別子として使用できる機能です。Upsert (アップサート) の実現:データローダやインポートウィザードには Upsert(存在すれば更新、なければ作成)という機能があります。外部IDを設定しておくと、インポート時に**「レコードの照合にどの項目を使いますか?」**と聞かれ、PrimaryId__c を選択できます。効率化のポイント:これを使えば、事前にSalesforceからレポートを出してレコードIDを調べたり(VLOOKUP)、複雑なコードを書いたりする必要が一切なくなります。不正解の解説A. CSV を candidate__c に関連するカスタム オブジェクトにアップロードします。理由: まったくの検討違いです。目的は「Candidate(候補者)レコード自体の更新」です。関連オブジェクト(例えば「応募履歴」など)にデータを入れても、親である候補者レコードの情報は更新されません。B. レコードを正しくマッピングするために挿入前トリガー (Before Insert Trigger) を作成します。理由: 過剰な開発 (Over-engineering) です。トリガーを使えば、「InsertされそうになったデータのIDを見て、既存レコードを検索し、あったらそちらを更新する」というロジックを作ることは技術的には可能です。デメリット:コードの記述とメンテナンスが必要です。大量データのインポート時、トリガー内でSOQLクエリを発行すると、ガバナ制限(SOQL発行回数など)に容易に抵触します。標準機能(C)で解決できることにコードを使うのは、Salesf...