Universal Containers (UC) は、Salesforce の注文をカスタム オブジェクト ord=xr < で処理します。また、営業担当者が一度に数千件の注文を含む CSV ファイルをアップロードすることもできます。
開発者は、Salesforce で行われた注文を UC のエンタープライズ リソース プランニング (ERP) システムに統合する任務を負っています。
注文のステータスが最初に「発注済み」に設定された後、注文情報は、一度に 1 つの注文を処理できる ERP システム内の REST エンドポイントに送信する必要があります。
これを実現するために開発者は何を実装する必要がありますか?
正解:D
To integrate Order__c records with the ERP system after their status is set to 'Placed', and considering that orders may be uploaded in bulk, the developer should:
Option D: Callout from a Queueable class called from a trigger
Trigger: Implement an after-update trigger on Order__c to detect when the status changes to 'Placed'.
Queueable Apex: Use Queueable Apex to handle asynchronous processing and callouts. Queueable classes support callouts by implementing the Database.AllowsCallouts interface.
Benefits:
Handles Bulk Data: Queueable Apex can process records in batches and can be chained for processing large volumes.
Supports Callouts: Unlike future methods, Queueable Apex allows for more complex data types and supports callouts with fewer limitations.
Reference:
"To make a Web service callout to an external service or API, you must use asynchronous Apex, such as future methods, Queueable Apex, or batch Apex."
"Queueable Apex is an asynchronous Apex feature that is a superset of future methods with some extra features."
- Apex Developer Guide: Queueable Apex
Why Other Options Are Incorrect:
Option A: Callout from an @future method called from a trigger
@future methods have limitations, such as accepting only primitive types as parameters and a limit of 50 calls per transaction, which can be exceeded when processing thousands of records.
"Methods with the future annotation must be static methods and can only return a void type. The specified parameters must be primitive data types, arrays of primitive data types, or collections of primitive data types."
- Apex Developer Guide: Future Methods
Option B: Callout from a Batchable class called from a scheduled job
Batch Apex is not immediately triggered by record changes and may not meet the requirement of processing the order after the status changes.
Scheduling adds delay and complexity unnecessary for this use case.
Option C: Flow with a callout from an invocable method
Flows invoked from triggers (record-triggered flows) cannot perform callouts unless they are configured to run asynchronously, and managing bulk operations with flows can be less efficient.