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

Batch リソース

最大 25 個のサブ要求から成るバッチを含むリクエストボディを作成し、1 つの要求としてサーバに送信して、アプリケーションのパフォーマンスを向上させます。バッチ内の各サブ要求のレスポンスボディと HTTP 状況は、1 つのレスポンスボディ内で返されます。各サブ要求は、レート制限にカウントされます。

このリソースは、クライアントとサーバ間の往復回数を最小限に抑えるために作成します。たとえば、モバイルアプリケーションで、ユーザがフィード項目にいいね! と言うためにボタンをタップすると、レスポンスボディにはいいね! に関する情報が含まれますが、フィード項目に対するいいね! の総数は含まれません。フィード項目にいいね! と言うには、POST で要求を /chatter/feed-elements/feedElementId/capabilities/chatter-likes/items に送信します。いいね! の合計を取得するには、GET で /chatter/feed-elements/feedElementId/capabilities/chatter-likes/items からフィード項目情報を取得します。

次のように、両方の要求を Generic Batch Collection Input リクエストボディに追加し、1 つの POST 要求で両方を /connect/batch に送信します。

1{
2   "batchRequests" : [
3    {
4       "method" : "Post",
5       "url" : "/v46.0/chatter/feed-elements/feedElementId/capabilities/chatter-likes/items"
6    },
7    {
8       "method" : "Get",
9       "url" : "/v46.0/chatter/feed-elements/feedElementId/capabilities/chatter-likes/items"
10    }
11   ],
12   "haltOnError" : "false"
13}

バッチ内の各要求はサブ要求と呼ばれます。サブ要求はすべて同じユーザのコンテキスト内で実行されます。各サブ要求は独立しており、相互に情報を渡すことはできません。サブ要求は、リクエストボディ内の順序に従って実行されます。サブ要求が正常に実行されると、データがコミットされます。コミットは、以降のサブ要求の出力に反映されます (前の例のように、フィード項目にいいね! と言ってから、いいね! の総数を取得するなど)。サブ要求が失敗した場合、前のサブ要求で行われたコミットはロールバックされません。

リソース
1/connect/batch
適用開始バージョン
28.0
Chatter が必要かどうか
いいえ
HTTP メソッド
POST
リクエストボディ
Generic Batch Collection Input
ルート XML タグ
<batch>
JSON
1{
2   "batchRequests" : [
3    {
4       "method" : "Get",
5       "url" : "/v46.0/chatter/feeds/news/me"
6    },
7    {
8       "method" : "Get",
9       "url" : "/v46.0/chatter/feeds/user-profile/me"
10    }
11   ]
12}
プロパティ
名前 説明 使用可能なバージョン
batchRequests Generic Batch Input[] 実行するサブ要求の URL を含む、Batch Request Input リクエストボディのコレクション。 28.0
haltOnError Boolean サブ要求が失敗した場合に、Salesforce がサブ要求の処理を停止するかどうかを制御します。デフォルト値は、false です。

値が false で、バッチ内のサブ要求が完了しない場合、Salesforce は、バッチ内の後続のサブ要求を実行しようと試みます。

値が true で、HTTP 応答 400 番台または 500 番台のエラーが含まれるためにバッチ内のサブ要求が完了しない場合、Salesforce は実行を停止します。バッチでは、後続のサブ要求の実行は試されません。また、前の要求が失敗したことを示す HTTP 412 状況コードと BATCH_PROCESSING_HALTED エラーメッセージが、後続のサブ要求ごとに返されます。/connect/batch への最上位要求は、HTTP 200 を返し、応答内の hasErrors プロパティが true に設定されます。

Salesforce は、サブ要求の実行前に、サブ要求も含めた要求全体が適切な形式になっていることを確認します。要求全体が適切な形式になっていない場合、Salesforce は HTTP 400 Bad Request を返し、haltOnError の値に関係なく、サブ要求を実行しません。不正な要求の例として、誤ったメソッドを使用するサブ要求、または URL にエラーがあるサブ要求を挙げることができます。

メモ

28.0
要求のパラメータ
なし。
応答
Batch Results
この例では、https://instance_name/services/data/v46.0/connect/batch に対する POST 要求に、2 つのサブ要求を持つ次のリクエストボディが含まれています。
1{
2   "batchRequests" : [
3    {
4       "method" : "Get",
5       "url" : "/v46.0/chatter/feeds/user-profile/me"
6    },
7    {
8       "method" : "Get",
9       "url" : "/v46.0/chatter/feeds/news/me"
10    }
11   ]
12}
Batch Results レスポンスボディには、サブ要求ごとに Batch Result Item レスポンスボディが含まれます。
1{
2   "hasErrors": false,
3   "results": [
4      {
5         "result": {
6            "feedElementPostUrl": "/services/data/v46.0/chatter/feed-elements",
7            "feedElementsUrl": "/services/data/v46.0/chatter/feeds
8/user-profile/005D0000001LL8OIAW/feed-elements",
9            "isModifiedUrl": null
10         },
11         "statusCode": 200
12      },
13      {
14         "result": {
15            "feedElementPostUrl": "/services/data/v46.0/chatter/feed-elements",
16            "feedElementsUrl": "/services/data/v46.0/chatter/feeds
17/news/005D0000001LL8OIAW/feed-elements",
18            "isModifiedUrl": null
19         },
20         "statusCode": 200
21      }
22   ]
23}
例: haltOnErrortrue の場合
これは前と同じ例ですが、最初のサブ要求にエラーが含まれ、haltOnErrortrue に設定されています。最初のサブ要求には入力ミスがあります。
1{
2   "batchRequests" : [
3    {
4       "method" : "Get",
5       "url" : "/v46.0/chatter/feeds/user-profile/men"
6    },
7    {
8       "method" : "Get",
9       "url" : "/v46.0/chatter/feeds/news/me"
10    }
11   ],
12   "haltOnError" : "true"
13}
Batch Results レスポンスボディには、サブ要求ごとに Batch Result Item レスポンスボディが含まれます。/connect/batch への最上位要求は HTTP 200 を返しますが、最初のサブ要求はリソースが見つからないため HTTP 404 を返します。haltOnErrortrue であるため、次のサブ要求は HTTP 412 を返します。また、hasErrorstrue に設定されています。
1{
2   "hasErrors": true,
3   "results": [
4      {
5         "result": [{
6            "errorCode": "NOT_FOUND",
7            "message": "The requested resource does not exist"
8         }],
9         "statusCode": 404
10      },
11      {
12         "result": [{
13            "errorCode": "BATCH_PROCESSING_HALTED",
14            "message": "Batch processing halted per request"
15         }],
16         "statusCode": 412
17      }
18   ]
19}
バイナリファイルを含む複数のコメントの投稿
この例は、2 つのサブ要求が含まれる https://instance_name/services/data/v46.0/connect/batch への汎用バッチ要求です。各サブ要求はフィード項目にコメントし、バイナリファイルをコメントにアップロードします。
richInput プロパティには、各サブ要求のリクエストボディを含めます。
また、binaryPartName および binaryPartNameAlias プロパティには、バイナリパートに関する情報を含めます。
次に cURL の例を示します。
1curl -H "X-PrettyPrint: 1" -F 'json={ "haltOnError":true, "batchRequests":[ { "url":"/v33.0/chatter/feed-elements/0D5D0000000YG0N/capabilities/comments/items", 
2"method":"Post", "binaryPartName":"binaryPart1", "binaryPartNameAlias":"feedElementFileUpload", "richInput":{ "body":{ "messageSegments":[ { "type":"Text", "text":"Check out this file, it may help." } ] },
3 "capabilities":{ "content":{ "title":"Presentation1.txt" } } } }, { "url":"/v33.0/chatter/feed-elements/0D5D0000000YG0M/capabilities/comments/items", 
4"method":"Post", "binaryPartName":"binaryPart2", "binaryPartNameAlias":"feedElementFileUpload", "richInput":{ "body":{ "messageSegments":[ { "type":"Text", "text":"Check out this file, it may help." } ] },
5 "capabilities":{ "content":{ "title":"Presentation2.txt" } } } } ] };type=application/json' -F "binaryPart1=@/Users/jbleyle/Desktop/Presentation1.txt;type=application/octet-stream" 
6-F "binaryPart2=@/Users/jbleyle/Desktop/Presentation2.txt;type=application/octet-stream" 
7-X POST https://instance_name/services/data/v46.0/connect/batch 
8-H 'Authorization: OAuth 00DD00000007HoR!...' --insecure
次は、マルチパート/フォームデータリクエストボディです。
1https://instance_name/services/data/v46.0/connect/batch
2
3Authorization: OAuth 00DD0000000Jhd2!...
4Accept: application/json
5Host: instance_name
6Content-Type: multipart/form-data; boundary=123123
7
8--123123
9Content-Disposition: form-data; name="json"
10Content-Type: application/json
11
12{
13   "haltOnError":true,
14   "batchRequests":[
15      {
16         "url":"/v46.0/chatter/feed-elements/0D5D0000000YG0D/capabilities/comments/items",
17         "method":"Post",
18         "binaryPartName":"binaryPart1",
19         "binaryPartNameAlias":"feedElementFileUpload",
20         "richInput":{
21            "body":{
22               "messageSegments":[
23                  {
24                     "type":"Text",
25                     "text":"Check out this file, it may help."
26                  }
27               ]
28            },
29            "capabilities":{
30               "content":{
31                  "title":"Presentation1.txt"
32               }
33            }
34         }
35      },
36      {
37         "url":"/v46.0/chatter/feed-elements/0D5D0000000YG0H/capabilities/comments/items",
38         "method":"Post",
39         "binaryPartName":"binaryPart2",
40         "binaryPartNameAlias":"feedElementFileUpload",
41         "richInput":{
42            "body":{
43               "messageSegments":[
44                  {
45                     "type":"Text",
46                     "text":"Check out this file, it may help."
47                  }
48               ]
49            },
50            "capabilities":{
51               "content":{
52                  "title":"Presentation2.txt"
53               }
54            }
55         }
56      }
57   ]
58}
59
60
61--123123
62Content-Disposition: form-data; name="binaryPart1"; filename="Presentation1.txt"
63Content-Type: application/octet-stream; charset=ISO-8859-1
64Content-Transfer-Encoding: binary
65
66This is the content of file 1
67--123123
68Content-Disposition: form-data; name="binaryPart2"; filename="Presentation2.txt"
69Content-Type: application/octet-stream; charset=ISO-8859-1
70Content-Transfer-Encoding: binary
71
72This is the content of file 2
73--123123--