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

一括クエリの使用

一括クエリジョブにバッチを追加するときに、要求のヘッダーの Content-Type には、ジョブの作成時に指定されたコンテンツタイプに応じて、text/csv または application/xml のいずれかを指定する必要があります。バッチに使用される実際の SOQL ステートメントは、平文テキスト形式で表されます。

URI
https://instance_name—api.salesforce.com/services/async/APIversion/job/jobid/batch
一括クエリの要求
1POST baseURI/job/750x00000000014/batch
2X-SFDC-Session: 4f1a00D30000000K7zB!ARUAQDqAHcM...
3Content-Type: [either text/csv or application/xml depending on job]
4
5[plain text SOQL statement]
Bulk API クエリでは、次の SOQL はサポートされていません。
  • COUNT
  • ROLLUP
  • SUM
  • GROUP BY CUBE
  • OFFSET
  • ネストされた SOQL クエリ
  • リレーション項目

また、Bulk API は、複合住所項目または複合地理位置情報項目へのアクセスやクエリができません。

メモ

SOAP のヘッダー、要求および応答

一括クエリの要求と応答の例を次に示します。

一括クエリバッチ作成の HTTP 要求
1POST baseURI/job/750x00000000014/batch
2X-SFDC-Session: 4f1a00D30000000K7zB!ARUAQDqAHcM...
3Content-Type: text/csv; charset=UTF-8
4
5SELECT Name, Description__c FROM Merchandise__c
一括クエリバッチ作成の HTTP レスポンスボディ
1<?xmlversion="1.0" encoding="UTF-8"?>
2<batchInfo
3  xmlns="http://www.force.com/2009/06/asyncapi/dataload">
4    <id>751x00000000079AAA</id>
5    <jobId>750x00000000014</jobId>
6    <state>Queued</state>
7    <createdDate>2009-09-01T17:44:45.000Z</createdDate>
8    <systemModstamp>2009-09-01T17:44:45.000Z</systemModstamp>
9    <numberRecordsProcessed>0</numberRecordsProcessed>
10</batchInfo>
バッチ結果取得の HTTP 要求
1GET baseURI/job/750x00000000014/batch/751x00000000030/result
2X-SFDC-Session: 4f1a00D30000000K7zB!ARUAQDqAHcM...
バッチ結果取得の HTTP レスポンスボディ
1<result-list xmlns="http://www.force.com/2009/06/asyncapi/dataload"><result>752x000000000F1</result></result-list>
一括クエリ結果取得の HTTP 要求
1GET baseURI/job/750x00000000014/batch/751x00000000030/result/752x000000000F1
2X-SFDC-Session: 4f1a00D30000000K7zB!ARUAQDqAHcM...
一括クエリ結果取得の HTTP レスポンスボディ
1"Name", "Description__c"
2"Merchandise1", "Description for merchandise 1"
3"Merchandise2", "Description for merchandise 2"

WSC を使用した Java の例

次の例では、Partner API を使用して組織にログインし、Partner API ログインからサービスエンドポイントを使用して BulkConnection オブジェクトをインスタンス化します。

1public boolean login() {
2    boolean success = false;
3    
4    String userId = getUserInput("UserID: ");
5    String passwd = getUserInput("Password: ");
6    String soapAuthEndPoint = "https://" + loginHost + soapService;
7    String bulkAuthEndPoint = "https://" + loginHost + bulkService;
8    try {
9      ConnectorConfig config = new ConnectorConfig();
10      config.setUsername(userId);
11      config.setPassword(passwd);
12      config.setAuthEndpoint(soapAuthEndPoint);
13      config.setCompression(true);
14      config.setTraceFile("traceLogs.txt");
15      config.setTraceMessage(true);
16      config.setPrettyPrintXml(true);
17      System.out.println("AuthEndpoint: " + 
18          config.getRestEndpoint());
19      PartnerConnection connection = new PartnerConnection(config);
20      System.out.println("SessionID: " + config.getSessionId());
21      config.setRestEndpoint(bulkAuthEndPoint);
22      bulkConnection = new BulkConnection(config);
23      success = true;
24    } catch (AsyncApiException aae) {
25      aae.printStackTrace();
26    } catch (ConnectionException ce) {
27      ce.printStackTrace();
28    } catch (FileNotFoundException fnfe) {
29      fnfe.printStackTrace();
30    }
31    return success;
32  }
33  
34  public void doBulkQuery() {
35    if ( ! login() ) {
36      retirn;
37    }
38    try {
39      JobInfo job = new JobInfo();
40      job.setObject("Merchandise__c");
41      
42      job.setOperation(OperationEnum.query);
43      job.setConcurrencyMode(ConcurrencyMode.Parallel);
44      job.setContentType(ContentType.CSV);
45      
46      job = bulkConnection.createJob(job);
47      assert job.getId() != null;
48      
49      job = bulkConnection.getJobStatus(job.getId());
50      
51      String query = 
52          "SELECT Name, Id, Description__c FROM Merchandise__c";
53      
54      long start = System.currentTimeMillis();
55      
56      BatchInfo info = null;
57      ByteArrayInputStream bout = 
58          new ByteArrayInputStream(query.getBytes());
59      info = bulkConnection.createBatchFromStream(job, bout);
60      
61      String[] queryResults = null;
62      
63      for(int i=0; i<10000; i++) {
64        Thread.sleep(i==0 ? 30 * 1000 : 30 * 1000); //30 sec
65        info = bulkConnection.getBatchInfo(job.getId(), 
66            info.getId());
67        
68        if (info.getState() == BatchStateEnum.Completed) {
69          QueryResultList list = 
70              bulkConnection.getQueryResultList(job.getId(), 
71                  info.getId());
72          queryResults = list.getResult();
73          break;
74        } else if (info.getState() == BatchStateEnum.Failed) {
75          System.out.println("-------------- failed ----------" 
76              + info);
77          break;
78        } else {
79          System.out.println("-------------- waiting ----------" 
80              + info);
81        }
82      }
83      
84      if (queryResults != null) {
85        for (String resultId : queryResults) {
86          bulkConnection.getQueryResultStream(job.getId(), 
87              info.getId(), resultId);
88        }
89      }
90    } catch (AsyncApiException aae) {
91      aae.printStackTrace();
92    } catch (InterruptedException ie) {
93      ie.printStackTrace();
94    }
95  }