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

Newer Version Available

This content describes an older version of this product. View Latest

冪等実行

インテグレーションサービスをトリガーする API コールは、同じカートで複数回実行されることがよくあります。インテグレーション API は、カートを更新する前に、前のコールの結果をクリーンアップして解決する (冪等性) ように設計されています。失敗が発生すると、カートは再試行されます。通常はインテグレーションサービスまたはバイヤーアクションによってエラーが発生します。
インテグレーションは前の実行の部分結果を使用して実行できます。部分結果には null 値と非 null 値が混在します。更新された値を書き込む前に、コードでは前の実行のインテグレーション結果がクリーンアップされます。

このインテグレーション例は、すべての品目の価格を一括書き込みでクリアしてから、価格の再計算を試みます。

1public class CartPriceCalcImpl implements checkout_CartPriceCalc {
2
3  IntegrationStatus startCartProcessAsync(IntegrationInfo jobInfo, ID cartId) {   
4
5     // clean previous executions
6     cleanItemPrices(jobInfo, cartId);
7
8     // bulk update prices
9     bulkUpdateItems(jobInfo, cartId);
10    
11     // indicate to the service, that the work is complete
12     IntegrationStatus.complete();
13  }
14
15  public void cleanItemPrices(IntegrationInfo jobInfo, ID cartId) {
16 
17     // execute integration work on the calling thread
18     List<CartItem> cartItems =
19          [ SELECT CartItemId, SKU, Quantity, TotalLineAmount
20            FROM CartItem
21            WHERE WebCartId = cartId ];
22
23     // for each set price
24     for(Cartitem cartItem : cartItems) {
25        cartItem.TotalLineAmount = null;
26     }
27
28     // bulk update of cart items
29     update cartItems;
30  }
31
32  ...
33}
34