function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Apex Callout


   Since apex callouts are asynchronous, can I have a trigger that will prevent a record from being saved if the return value of the callout meets a certain criteria?


An example being:

  When a record is being saved, the trigger calls out to a web service using the value in one of the fields on that record.  If the web service returns 0 I want the record to not be allowed to be saved.  If the record returns a 1 I want the record to be saved.  


Anyone have experience with matters such as this? 


Hey Rs,


You can write a trigger and do the call in loop like


//Do your callout


//Check for result here

if(Account tr : {


//condition satisfies

insert tr;


else {


//Here adding error message when condition matches using label




You can create an error message for the trigger on detail page using custom labels


Here is the link too






  I appreciate your response.  I am a little confused though.  From what I have been researching, all callouts are annotated with @future which means that the callout method will run after the trigger has long finished.  Otherwise, the record save would be held up waiting for the response from the service.