[SalesForce] HOW we Send apex REST Request IN XML Formate to an external URL and Parse XML Response

i am in middle of a integration with external system in Salesforce.
My requirement is to send an XML Request to an Endpoint and also Parse xml Response got from endpoint to create some Contact object record.

Best Answer

You can utilize standard Http Classes here.

To be able to send the request, you just need to set the Content-Type to XML. Assuming you already have the XML created, you can just use the below snippet to send the request.

Http h = new Http();
HttpRequest req = new HttpRequest();
req.setContentType('Content-Type', 'text/xml');

And then once you get the response, you can accordingly use the Document class to parse the response.

String xml = httpResponse.getBody();
Dom.Document domDoc = new Dom.Document(xml);

You should look more on the specific documentations to get started.

Related Topic