Development questions
Can we make a synchronous web service callout directly from a trigger? Why or why not?
No. Salesforce does not allow synchronous callouts from a trigger: the transaction holds database locks while uncommitted, and a slow external call would keep them open and hurt the platform. You get an error like Callout from triggers are currently not supported.
Make the callout asynchronously with @future(callout=true) or a Queueable class implementing Database.AllowsCallouts, called from the trigger or its handler.
apex-triggertriggercallout
More Development questions
- What is an Apex Trigger in Salesforce and when should you use it over Flows?
- What is the difference between before triggers and after triggers?
- Explain all Trigger context variables (isInsert, isUpdate, isDelete, isUndelete, isBefore, isAfter, isExecuting, size, operationType).
- What is the difference between Trigger.new and Trigger.old?
- In which trigger events are Trigger.new and Trigger.newMap available?
- In which trigger events are Trigger.old and Trigger.oldMap available?