一括クエリサンプルの説明
ジョブの作成
- 次のテキストを含む、create-job.xml というファイルを作成します。
1<?xml version="1.0" encoding="UTF-8"?> 2<jobInfo 3 xmlns="http://www.force.com/2009/06/asyncapi/dataload"> 4 <operation>query</operation> 5 <object>Account</object> 6 <concurrencyMode>Parallel</concurrencyMode> 7 <contentType>CSV</contentType> 8</jobInfo> - コマンドラインウィンドウを使用して、次の cURL コマンドを実行し、新しいジョブを作成します。
curl -H "X-SFDC-Session: sessionId" -H "Content-Type: application/xml; charset=UTF-8" -d @create-job.xml https://instance.salesforce.com/services/async/42.0/job
instance は、ログインの応答でメモした <serverUrl> 要素の一部分です。sessionId は同様にメモした <sessionId> 要素です。
Salesforce により、次のようなデータを含む XML 応答が返されます。
1<?xml version="1.0" encoding="UTF-8"?> 2<jobInfo 3 xmlns="http://www.force.com/2009/06/asyncapi/dataload"> 4 <id>750x000000009tvAAA</id> 5 <operation>query</operation> 6 <object>Account</object> 7 <createdById>005x0000001WR0lAAG</createdById> 8 <createdDate>2016-01-10T00:53:19.000Z</createdDate> 9 <systemModstamp>2016-01-10T00:53:19.000Z</systemModstamp> 10 <state>Open</state> 11 <concurrencyMode>Parallel</concurrencyMode> 12 <contentType>CSV</contentType> 13 <numberBatchesQueued>0</numberBatchesQueued> 14 <numberBatchesInProgress>0</numberBatchesInProgress> 15 <numberBatchesCompleted>0</numberBatchesCompleted> 16 <numberBatchesFailed>0</numberBatchesFailed> 17 <numberBatchesTotal>0</numberBatchesTotal> 18 <numberRecordsProcessed>0</numberRecordsProcessed> 19 <numberRetries>0</numberRetries> 20 <apiVersion>36.0</apiVersion> 21 <numberRecordsFailed>0</numberRecordsFailed> 22 <totalProcessingTime>0</totalProcessingTime> 23 <apiActiveProcessingTime>0</apiActiveProcessingTime> 24 <apexProcessingTime>0</apexProcessingTime> 25</jobInfo>
ジョブへのバッチの追加
- SOQL クエリステートメントを含む、query.txt というファイルを作成します。
1SELECT Id, Name FROM Account LIMIT 10 - コマンドラインウィンドウを使用して、次の cURL コマンドを実行し、ジョブにバッチを追加します。
curl -d @query.txt -H "X-SFDC-Session: sessionId" -H "Content-Type: text/csv; charset=UTF-8" https://instance.salesforce.com/services/async/42.0/job/jobId/batch
jobId は、ジョブ作成の応答で返されたジョブ ID です。
Salesforce により、次のようなデータを含む XML 応答が返されます。
1<?xml version="1.0" encoding="UTF-8"?> 2<batchInfo 3 xmlns="http://www.force.com/2009/06/asyncapi/dataload"> 4 <id>751x000000009vwAAA</id> 5 <jobId>750x000000009tvAAA</jobId> 6 <state>Queued</state> 7 <createdDate>2016-01-10T00:59:47.000Z</createdDate> 8 <systemModstamp>2016-01-10T00:59:47.000Z</systemModstamp> 9 <numberRecordsProcessed>0</numberRecordsProcessed> 10 <numberRecordsFailed>0</numberRecordsFailed> 11 <totalProcessingTime>0</totalProcessingTime> 12 <apiActiveProcessingTime>0</apiActiveProcessingTime> 13 <apexProcessingTime>0</apexProcessingTime> 14</batchInfo>
ジョブとバッチの状況の確認
- コマンドラインウィンドウを使用して、次の cURL コマンドを実行し、ジョブの状況を確認します。
curl -H "X-SFDC-Session: sessionId" https://instance.salesforce.com/services/async/42.0/job/jobId
Salesforce により、次のようなデータを含む XML 応答が返されます。
1<?xml version="1.0" encoding="UTF-8"?> 2<jobInfo 3 xmlns="http://www.force.com/2009/06/asyncapi/dataload"> 4 <id>750x000000009tvAAA</id> 5 <operation>query</operation> 6 <object>Account</object> 7 <createdById>005x0000001WR0lAAG</createdById> 8 <createdDate>2016-01-10T00:53:19.000Z</createdDate> 9 <systemModstamp>2016-01-10T00:53:19.000Z</systemModstamp> 10 <state>Open</state> 11 <concurrencyMode>Parallel</concurrencyMode> 12 <contentType>CSV</contentType> 13 <numberBatchesQueued>0</numberBatchesQueued> 14 <numberBatchesInProgress>0</numberBatchesInProgress> 15 <numberBatchesCompleted>1</numberBatchesCompleted> 16 <numberBatchesFailed>0</numberBatchesFailed> 17 <numberBatchesTotal>1</numberBatchesTotal> 18 <numberRecordsProcessed>10</numberRecordsProcessed> 19 <numberRetries>0</numberRetries> 20 <apiVersion>36.0</apiVersion> 21 <numberRecordsFailed>0</numberRecordsFailed> 22 <totalProcessingTime>0</totalProcessingTime> 23 <apiActiveProcessingTime>0</apiActiveProcessingTime> 24 <apexProcessingTime>0</apexProcessingTime> 25</jobInfo> - コマンドラインウィンドウを使用して、次の cURL コマンドを実行し、バッチの状況を確認します。
curl -H "X-SFDC-Session: sessionId" https://instance.salesforce.com/services/async/42.0/job/jobId/batch/batchId
batchId は、バッチ作成の応答で返されたバッチ ID です。
Salesforce により、次のようなデータを含む XML 応答が返されます。
1<?xml version="1.0" encoding="UTF-8"?> 2<batchInfo 3 xmlns="http://www.force.com/2009/06/asyncapi/dataload"> 4 <id>751x000000009vwAAA</id> 5 <jobId>750x000000009tvAAA</jobId> 6 <state>Completed</state> 7 <createdDate>2016-01-10T00:59:47.000Z</createdDate> 8 <systemModstamp>2016-01-10T01:00:19.000Z</systemModstamp> 9 <numberRecordsProcessed>10</numberRecordsProcessed> 10 <numberRecordsFailed>0</numberRecordsFailed> 11 <totalProcessingTime>0</totalProcessingTime> 12 <apiActiveProcessingTime>0</apiActiveProcessingTime> 13 <apexProcessingTime>0</apexProcessingTime> 14</batchInfo>
結果の取得
- コマンドラインウィンドウを使用して、次の cURL コマンドを実行し、バッチ結果のリストを取得します。
curl -H "X-SFDC-Session: sessionId" https://instance.salesforce.com/services/async/42.0/job/jobId/batch/batchId/result
Salesforce により、次のようなデータを含む XML 応答が返されます。
1<?xml version="1.0" encoding="UTF-8"?> 2<result-list xmlns="http://www.force.com/2009/06/asyncapi/dataload"> 3 <result>752x00000004CJE</result> 4</result-list> - コマンドラインウィンドウを使用して、次の cURL コマンドを実行し、クエリの結果を取得します。
curl -H "X-SFDC-Session: sessionId" https://instance.salesforce.com/services/async/42.0/job/jobId/batch/batchId/result/resultId
resultId は、バッチ結果リストの要求に対する応答で返された結果 ID です。
Salesforce により、次のようなデータを含む CSV 応答が返されます。
1"Id","Name" 2"001x000xxx4TU4JAAW","name161268--1296595660659" 3"001x000xxx4TU4KAAW","name161269--1296595660659" 4"001x000xxx4TU4LAAW","name161270--1296595660659" 5"001x000xxx4TU4MAAW","name161271--1296595660659" 6"001x000xxx4TU4NAAW","name161272--1296595660659" 7"001x000xxx4TU4OAAW","name161273--1296595660659" 8"001x000xxx4TU4PAAW","name161274--1296595660659" 9"001x000xxx4TU4QAAW","name161275--1296595660659" 10"001x000xxx4TU4RAAW","name161276--1296595660659" 11"001x000xxx4TU4SAAW","name161277--1296595660659"
ジョブの終了
- 次のテキストを含む、close-job.xml というファイルを作成します。
1<?xml version="1.0" encoding="UTF-8"?> 2<jobInfo xmlns="http://www.force.com/2009/06/asyncapi/dataload"> 3 <state>Closed</state> 4</jobInfo> - コマンドラインウィンドウを使用して、次の cURL コマンドを実行し、ジョブを終了します。
curl -H "X-SFDC-Session: sessionId" -H "Content-Type: text/csv; charset=UTF-8" -d @close-job.xml https://instance.salesforce.com/services/async/42.0/job/jobId
Salesforce により、次のようなデータを含む XML 応答が返されます。
1<?xml version="1.0" encoding="UTF-8"?> 2<jobInfo 3 xmlns="http://www.force.com/2009/06/asyncapi/dataload"> 4 <id>750x000000009tvAAA</id> 5 <operation>query</operation> 6 <object>Account</object> 7 <createdById>005x0000001WR0lAAG</createdById> 8 <createdDate>2016-01-10T00:53:19.000Z</createdDate> 9 <systemModstamp>2016-01-10T00:53:19.000Z</systemModstamp> 10 <state>Closed</state> 11 <concurrencyMode>Parallel</concurrencyMode> 12 <contentType>CSV</contentType> 13 <numberBatchesQueued>0</numberBatchesQueued> 14 <numberBatchesInProgress>0</numberBatchesInProgress> 15 <numberBatchesCompleted>1</numberBatchesCompleted> 16 <numberBatchesFailed>0</numberBatchesFailed> 17 <numberBatchesTotal>1</numberBatchesTotal> 18 <numberRecordsProcessed>10</numberRecordsProcessed> 19 <numberRetries>0</numberRetries> 20 <apiVersion>36.0</apiVersion> 21 <numberRecordsFailed>0</numberRecordsFailed> 22 <totalProcessingTime>0</totalProcessingTime> 23 <apiActiveProcessingTime>0</apiActiveProcessingTime> 24 <apexProcessingTime>0</apexProcessingTime> 25</jobInfo>