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.

  • 3
    Welcome to SFSE! Please take the tour and read How to Ask. As is, this question is probably too broad for this site (it also sounds to me like it should be two separate questions). If you've already tried to write some code yourself to solve your problem, including that code as part of your question usually helps make your question better received (because it shows that you've made an attempt and have put effort into it, instead of asking for others to do your work for you). You can add this information by making an edit to your question.
    – Derek F
    Sep 17, 2018 at 12:37

1 Answer 1


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.

  • Yes I have created XML Doccument and sent it to External Endpoint successfully.Now i have to read response XML Doccument which have multiple data, Sep 18, 2018 at 10:55
  • You can use the standard XML reader/Document classes. Take a look on respective documentation and that should help. To consume the response, its already in the answer as how you can do that.
    – Jayant Das
    Sep 18, 2018 at 12:18
  • @JayantDas I am also trying to use xml with HTTPRequest. Can you suggest me some documents from where I can send a request with XML body. I want to know how we can create XML to be sent with the request.
    – Aakriti.G
    Dec 2, 2019 at 9:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .