+ Start a Discussion
rohit singh 92rohit singh 92 

HttpCallout and their response in json handling in trigger

i am creating a trigger using "after insert contact" event in which i want to verify the contact data with a accurateAppend api .
this api provides response in JSON format . 
but on developer console is giving an error "Callout from Triggers are currently not supported" .
i tried it to solve using @future notation .. but for @future notation the return type of function should be void .  but i want the response .. 
can anyone please guide me how to tackle this issue ?
Vasani ParthVasani Parth
Rohit,

try using @future(callout=true)

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_annotation_future.htm (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_annotation_future.htm)

The following snippet shows how to specify that a method executes a callout:
@future (callout=true) 
public static void doCalloutFromFuture()
{
//Add code to perform callout 
​}

You can specify (callout=false) to prevent a method from making callouts.When the callout is done you can get a status 200 code or some response body reponse and make sure the handshake was complete !!!

If you want to give the user an idea of the handshake I would suggest create a child object and create a field like " Status of transcation" and insert the response body/ response status code in the field.

To get something from the other end spin up a Rest Endpoint with a httppost method and provide the endpoint to the other vendor so that he can send the data back to you once the transaction is complete at his end.
This way you do not have to wait for the transaction to complete and use future for making callouts!!!

Please mark this as the best answer if this helps