A logistics company needs to notify its warehouse system through a REST callout whenever a Shipment__c record is inserted. The developer added the callout directly to an after insert trigger, and inserts now fail with a CalloutException. Which approach should the architect recommend?
- Move the callout into a before insert trigger so it runs before the DML is committed.
- Wrap the callout in a Continuation object invoked from the trigger handler.
- Enqueue a Queueable class that implements Database.AllowsCallouts and pass it the new record Ids.
- Add the warehouse endpoint to Remote Site Settings so the trigger is allowed to call it.
Show answer
Answer: C
Why: Apex triggers cannot perform synchronous callouts. Move the callout to asynchronous Apex, such as a Queueable implementing Database.AllowsCallouts or an @future(callout=true) method.