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

Batch リソース

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

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

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

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

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

サブ要求と一緒にバイナリファイルをアップロードするには、ファイルをマルチパート/フォームデータ要求のボディパートとして送信し、リクエストボディの richInput オブジェクトにファイルに関する情報を含めます。バイナリファイルのアップロードを参照してください。

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

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

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

28.0
要求パラメータ
なし。
応答
Batch Results
この単純な例では、https://instance_name/services/data/v32.0/connect/batch に対する POST 要求に、2 つのサブ要求を持つ次のリクエストボディが含まれています。
1swfobject.registerObject("clippy.codeblock-3", "9");{
2   "batchRequests" : [
3    {
4       "method" : "Get",
5       "url" : "/v32.0/chatter/feeds/user-profile/me"
6    },
7    {
8       "method" : "Get",
9       "url" : "/v32.0/chatter/feeds/news/me"
10    }
11   ]
12}
Batch Results レスポンスボディには、サブ要求ごとに Batch Result Item レスポンスボディが含まれます。
1swfobject.registerObject("clippy.codeblock-4", "9");{
2   "hasErrors": false,
3   "results": [
4      {
5         "result": {
6            "feedElementPostUrl": "/services/data/v32.0/chatter/feed-elements",
7            "feedElementsUrl": "/services/data/v32.0/chatter/feeds
8/user-profile/005D0000001LL8OIAW/feed-elements",
9            "feedItemsUrl": "/services/data/v32.0/chatter/feeds
10/user-profile/005D0000001LL8OIAW/feed-items",
11            "isModifiedUrl": null
12         },
13         "statusCode": 200
14      },
15      {
16         "result": {
17            "feedElementPostUrl": "/services/data/v32.0/chatter/feed-elements",
18            "feedElementsUrl": "/services/data/v32.0/chatter/feeds
19/news/005D0000001LL8OIAW/feed-elements",
20            "feedItemsUrl": "/services/data/v32.0/chatter/feeds
21/news/005D0000001LL8OIAW/feed-items",
22            "isModifiedUrl": null
23         },
24         "statusCode": 200
25      }
26   ]
27}
例: haltOnErrortrue の場合
これは前と同じ例ですが、最初のサブ要求にエラーが含まれ、haltOnErrortrue に設定されています。最初のサブ要求には入力ミスがあります。
1swfobject.registerObject("clippy.codeblock-5", "9");{
2   "batchRequests" : [
3    {
4       "method" : "Get",
5       "url" : "/v32.0/chatter/feeds/user-profile/men"
6    },
7    {
8       "method" : "Get",
9       "url" : "/v32.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 に設定されています。
1swfobject.registerObject("clippy.codeblock-6", "9");{
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 つのサブ要求が含まれるバッチ要求です。各サブ要求はフィード項目を作成し、フィード項目に添付するバイナリファイルをアップロードします。

POST 要求が https://instance_name/services/data/v32.0/connect/batch に対して行われます。

これは、マルチパート/フォームデータリクエストボディです。

1swfobject.registerObject("clippy.codeblock-7", "9");--123123
2Content-Disposition: form-data; name="json"
3Content-Type: application/json
4
5{
6    "haltOnError": "true",
7    "batchRequests": [
8        {
9            "method": "Post",
10            "url": "/v32.0/chatter/feeds/news/me/feed-items",
11            "binaryPartName": "binaryPart0",
12            "binaryPartNameAlias": "feedItemFileUpload",
13            "richInput": {
14                "attachment": {
15                    "attachmentType": "NewFile",
16                    "description": "description0",
17                    "title": "contentFile0"
18                },
19                "body": {
20                    "messageSegments": [
21                        {
22                            "type": "Text",
23                            "text": "textValue0"
24                        }
25                    ]
26                }
27            }
28        },
29        {
30            "method": "Post",
31            "url": "/v32.0/chatter/feeds/news/me/feed-items",
32            "binaryPartName": "binaryPart1",
33            "binaryPartNameAlias": "feedItemFileUpload",
34            "richInput": {
35                "attachment": {
36                    "attachmentType": "NewFile",
37                    "description": "description1",
38                    "title": "contentFile1"
39                },
40                "body": {
41                    "messageSegments": [
42                        {
43                            "type": "Text",
44                            "text": "textValue1"
45                        }
46                    ]
47                }
48            }
49        }
50    ]
51}
52--123123
53Content-Disposition: form-data; name="binaryPart0"; filename="file1.txt"
54Content-Type: application/octet-stream; charset=ISO-8859-1
55Content-Transfer-Encoding: binary
56
57This is content of file 1
58--123123
59Content-Disposition: form-data; name="binaryPart1"; filename="file2.txt"
60Content-Type: application/octet-stream; charset=ISO-8859-1
61Content-Transfer-Encoding: binary
62
63This is the content of file 2
64--123123--
65