[SalesForce] Send Response back to same url after receiving data from callout

Http http = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint(EndpointUrl);
req.setMethod('POST');
req.setBody(xmlstring);
req.setHeader('Content-Type', 'application/xml'); 
HttpResponse res = http.send(req);
string xmlresponse=res.getBody();

I am getting data and it is working fine but i need to send success message and some data to same url as i received data from server.

Is there any way to do that

Please help me out.

Best Answer

You can do that by sending response to the application making the call to your web service. Here is an example:

    RestResponse res = RestContext.response;
    res.statusCode = 200; //Signifies OK
    jsonResponse = '{"response": {"Data": "Value", "Data": "Value"}}';
    res.responseBody = blob.valueOf(jsonResponse);
    return;

Add the above code after the point when you have received and saved the data incoming from the web service.

Let me know if it works for you.

Happy Coding!!

Related Topic