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
Kumar_14279Kumar_14279 

Track the response of webservice callout in the trigger before insert

How to create a record based on the response of webservice call, when the data of the record being created needs to be passed in the  webservice callout?

 

Please let me know your thoughts.

 

Thanks and regards,

Kumar

Best Answer chosen by Admin (Salesforce Developers) 
aalbertaalbert

Are you invoking the web service callout in a trigger on the create of a record? If so, you can create the record in the object and then perform the @future async method that performs the callout.

 

From your post, it sounds like you don't want to create the record until after the callout returns. And since a callout within a trigger must execute asynchronously, you could store the record in a secondary custom object, execute the callout, and the response of the callout invokes a trigger on the secondary custom object to move the data over to the primary object.

 

Or probably a better solution would be to enter the data in a Visualforce page which can execute the callout synchronously and insert the salesforce record after the callout returns. 

All Answers

aalbertaalbert

Are you invoking the web service callout in a trigger on the create of a record? If so, you can create the record in the object and then perform the @future async method that performs the callout.

 

From your post, it sounds like you don't want to create the record until after the callout returns. And since a callout within a trigger must execute asynchronously, you could store the record in a secondary custom object, execute the callout, and the response of the callout invokes a trigger on the secondary custom object to move the data over to the primary object.

 

Or probably a better solution would be to enter the data in a Visualforce page which can execute the callout synchronously and insert the salesforce record after the callout returns. 

This was selected as the best answer
RavitejaRaviteja

Hi,

 iam working on same issue. My requirment is to create records in some object using json values.

            lastname=json.value;

        

thanks and regards,

Raviteja.