Salesforce Certified Platform Developer II — Question 208
Instead of waiting to send emails to support personnel directly from the finish method of a batch Apex process, Universal Containers wants to notify an external system in the event that an unhandled exception occurs.
What is the appropriate publish/subscribe logic to meet this requirement?
Answer options
- A. Publish the error event using the addError() method and write a trigger to subscribe to the event and notify the external system.
- B. Publish the error event using the addError() method and have the external system subscribe to the event using CometD.
- C. Publish the error event using the Eventbus.publish() method and have the external system subscribe to the event using CometD.
- D. No publishing is necessary. Have the external system subscribe to the BatchApexErrorEvent.
Correct answer: D
Explanation
The correct answer is D because the external system can directly subscribe to the BatchApexErrorEvent without the need for additional publishing. Options A, B, and C incorrectly suggest using addError() or Eventbus.publish(), which are not necessary in this context since the external system can directly listen for the error events.