# Salesforce Import Integration SalesforceとTreasure Dataを接続することで、Salesforceデータをより詳細に制御し、マーケティングおよびセールスオペレーションスタック内の他のビジネスアプリケーションとのより良い統合が可能になります。 SalesforceとTreasure Dataを統合することで、以下のことが簡単になります: - **Salesforceに新しい機能を追加する。** たとえば、Web利用状況を追跡し、顧客の製品使用量が減少したときにアラートを受け取ることで、チャーンを防ぐことができます。 - **Salesforceデータを使用してマーケティングスタックの他の部分を改善する。** たとえば、新規顧客をFacebook Custom Audiencesから自動的に削除することで、Facebook Ads ROIを向上させることができます。 Salesforceからデータをインポートするサンプルワークフローについては、[Treasure Boxes](https://github.com/treasure-data/treasure-boxes/tree/master/td_load/sfdc)を参照してください。 Treasure Dataアカウントをお持ちでない場合は、[お問い合わせ](https://www.treasuredata.com/contact_us/)いただければセットアップいたします。 ## 制限事項 - **SOQL:** この設定では、カスタムSOQL(Salesforce Object Query Language)を使用してデータをクエリおよびフィルタリングできます。SOQLを使用すると、単一のオブジェクトまたは相互に関連する複数のオブジェクトからデータを取得できます。特定の列を選択し、条件文で出力をフィルタリングまたはソートできます。制限として、データコネクタは*count() FROM Object*や*SELECT * from salesforceObject*などのSOQL構文をサポートしていません。 - **Bulk API制限:** Bulk APIはより高速な取り込みを提供しますが、24時間以内に10,000バッチの割り当て制限もあります。ターゲットが大きい場合、利用可能なバッチ割り当て全体が消費され、最終的にジョブが失敗する可能性があります。Bulk APIを使用しようとして、すべてのレコードを取り込む結果になった場合は、**synchronous transfer-only**オプションを有効にしてREST APIを使用することを検討してください。REST APIはバッチ割り当ての制限を回避しますが、速度が遅くなる可能性があります。 - **LIMIT句を含むSOQL:** SOQL クエリはBulk APIモードでLIMIT句と正しく機能しません。Bulk APIは大量のデータを処理するために特別に設計されています。LIMIT句を使用するには、代わりにREST APIを使用することが不可欠です。 - **OAuth**: OAuthはカスタムドメインをサポートしていません。したがって、カスタムドメインを使用している場合は、認証方法として資格情報を使用してください。 ## サポート SFDCインポートは以下の認証タイプをサポートしています: - Credential - **ユーザー名とパスワードフローを有効化:** SETTINGS → Identity → OAuth and OpenID Connect Settings → Allow OAuth Username-Password Flows (オンにする) - **OAuth Policies:** PLATFORM TOOLS → App → Connected Apps → Manage Connected Apps → Choose App → Edit Policies → Permitted Users (選択: All users may self-authorize) - OAuth インポートでは**Session IDによる認証**はサポートされていません。 Session IDは[Salesforce Export Integration](/ja/int/salesforce-export-integration)でのみサポートされています。 ## TD Consoleを使用してSalesforceに接続 TD Consoleを使用してSalesforceに接続するのは迅速かつ簡単です。または、コマンドラインを使用してSalesforce接続を作成することもできます。インポート統合は資格情報をサポートしています。資格情報を使用して認証するには、クライアントIDとクライアントシークレットが必要です。 ## Salesforceを使用してTDがSalesforceにアクセスできるようにする これらの手順は、資格情報を使用して認証するために必要なクライアントIDとクライアントシークレットを見つける方法を説明します。 これはLightning Experience UIのガイドです。 1. **Setup** > **Apps** > **App Manager**に移動します。 2. **New Connected App**を選択します。 3. いくつかの値を設定し、**Enable OAuth Settings**をチェックします。次に、OAuth権限スコープを付与します。![](/assets/oauth_setting.7fc14f2db75ac78c8f2ac3de705e2fab32f3eb4f5209915dc51d425433ace4aa.3074136a.png) 4. **Save**をクリックします。アクティベーションには最大10分かかる場合があります。 5. **Setup** > **Apps** > **App Manager**に移動します。 6. 接続されたアプリを見つけ、**▼**をクリックして、**View**を選択します。 ![](/assets/connected_app.9e63c75823ffc511c1015194c179433b8099f9f358711098a1699ee6e4f1bed8.3074136a.png) 7. **Consumer Key** (client_id)と**Consumer Secret** (client_secret)を書き留めるかコピーします。 ![](/assets/crient_secret.34a2b6324e27f53438e82f7a396c84b094c94c190bc093a92ddbf504fc0c7bd3.3074136a.png) ## TD Consoleで新しい接続を作成 1. **TD Console**を開きます。 2. **Integrations Hub** > **Catalog**に移動し、**Salesforce**を検索します。 3. 以下のいずれかを選択します: Authenticate with Credentials 1. 資格情報で認証するには、ユーザー名(メール)とパスワード、およびClient ID、Client Secret、Security Tokenを入力します。 2. ダイアログボックスで、ログインURLとして[login.salesforce.com](https://login.salesforce.com/)を入力します。Login URLパラメータから不要な文字を削除します。 ![](/assets/image-20200703-001720.af452b1f9ec571b64403178a495107a980e547d907f48f30614cf4b53843e7ed.d00a286f.png) Authenticate with OAuth ![](/assets/image-20201029-003333.3c371aa8231f40a349fe8bb1f49641b0c7abe05195705af5e11af1a6027b1d1c.d00a286f.png) 1. **Continue**を選択します。 2. 接続に説明的な名前を付けて、**Create Connection**を選択します。 ## Salesforce接続を検証 ユーザー権限を検証するには、Salesforceを使用して以下を検証してください: - Authority: Salesforceインポート統合の接続手順を確認してください。 - Treasure DataからSalesforceへのアクセスが許可されている: これを設定するには、TDの静的IPアドレスを知って設定する必要がある場合があります。静的IPアドレス情報が必要な場合は、サポートにお問い合わせください。 適切に設定された権限とアクセスがないと、アクセス制限エラーが発生する可能性があります。例えば: ``` Response not 2xx: 400 Bad Request {"error":"invalid_grant","error_description":"authentication failure"} ``` [Object and Field Permissions for Salesforce CRM in Data Cloud](https://help.salesforce.com/s/articleView?id=sf.c360_a_enable_user_permissions_external_salesforce_org.htm&type=5)の詳細をご覧ください。 ## SalesforceアカウントデータをTreasure Dataに転送 認証された接続を作成した後、自動的にAuthenticationsに移動します。 1. 作成した接続を検索します。 2. **New Source**を選択します。 3. Data Transferフィールドで**Source**の名前を入力します。 ![](/assets/image-20200710-205832.2c1ff801d788249554ab89bd4e24919ef34ff56a9aa225d3aff6de57181e008b.d00a286f.png) 4. **Next**をクリックします。 5. 以下のパラメータを編集します: ![](/assets/image-20200710-210028.37482785cab2d316edadd716f5eb88ee867bd570ec1f508e025977427fb834c5.d00a286f.png) | **Parameters** | **Description** | | --- | --- | | **Source** | インポートするオブジェクトの名前 | | **Include deleted records** | 削除されたレコードを含めることを有効にします | | **Use synchronous transfer only** | REST APIを使用した同期転送を有効にします | | **Incremental** | 前回のインポート以降の新しいデータのみをインポートします | ### **Data Settings** 1. **Next**を選択します。Data Settingsページが開きます。 2. ここでSOQLクエリ、WHERE条件、およびSchema設定を編集できます。 3. オプションで、ダイアログのこのページをスキップします。 ![](/assets/image-20200710-211039.6d38d12794407b568ad98bca8ab96943b9c044037c5e15c8dc249c258f62d7c4.d00a286f.png) ### Data Preview You can see a [preview](/products/customer-data-platform/integration-hub/batch/import/previewing-your-source-data) of your data before running the import by selecting Generate Preview. Data preview is optional and you can safely skip to the next page of the dialog if you choose to. 1. Select **Next**. The Data Preview page opens. 2. If you want to preview your data, select **Generate Preview**. 3. Verify the data. ### Data Placement For data placement, select the target database and table where you want your data placed and indicate how often the import should run. 1. Select **Next.** Under Storage, you will create a new or select an existing database and create a new or select an existing table for where you want to place the imported data. 2. Select a **Database** > **Select an existing** or **Create New Database**. 3. Optionally, type a database name. 4. Select a **Table**> **Select an existing** or **Create New Table**. 5. Optionally, type a table name. 6. Choose the method for importing the data. - **Append** (default)-Data import results are appended to the table. If the table does not exist, it will be created. - **Always Replace**-Replaces the entire content of an existing table with the result output of the query. If the table does not exist, a new table is created. - **Replace on New Data**-Only replace the entire content of an existing table with the result output when there is new data. 7. Select the **Timestamp-based Partition Key** column. If you want to set a different partition key seed than the default key, you can specify the long or timestamp column as the partitioning time. As a default time column, it uses upload_time with the add_time filter. 8. Select the **Timezone** for your data storage. 9. Under **Schedule**, you can choose when and how often you want to run this query. #### Run once 1. Select **Off**. 2. Select **Scheduling Timezone**. 3. Select **Create & Run Now**. #### Repeat Regularly 1. Select **On**. 2. Select the **Schedule**. The UI provides these four options: *@hourly*, *@daily* and *@monthly* or custom *cron*. 3. You can also select **Delay Transfer** and add a delay of execution time. 4. Select **Scheduling Timezone**. 5. Select **Create & Run Now**. After your transfer has run, you can see the results of your transfer in **Data Workbench** > **Databases.** ## FAQ ### Q. インポートされたレコードに`attributes`列が含まれていますが、SFDCにはそのようなパラメータがありません。これは何ですか? A. これはSFDCインポート統合が自動的に作成した列です。APIリクエストURIとターゲットオブジェクトが含まれています。