while consuming webservices in salesforce getting exception " System.CalloutException: Web service callout failed: Unexpected element. Parser was expecting element 'http://schemas.xmlsoap.org/soap/envelope/:Envelope' but found ':HTML'"


Check the Service URL, seems like it isn't pointing to a service. Try it in a browser.

Some services return the WSDL when suffixed with ?wsdl, good way to validate that the URL is right via the browser.

Also another one to check would be that the service URL is white listed under Remote Site Settings.


Its likely some kind of failure in the Web Service you are calling. Some Web Servers are configured to return a HTML error page (for us humans to read) even if the request was a Web Service and in fact should deserve the SOAP XML response representing the error (which is the correct response and hence what Salesforce expects).

The best way to see what is being sent back it to enable the Apex Debug logs. These contain the full HTTP request and response for you to view. This should let you know the response that is coming back and how to correct your request.

A debug log can record database operations, system processes, and errors that occur when executing a transaction or running unit tests. Debug logs can contain information about: Database changes

  • HTTP callouts

  • Apex errors

  • Resources used by Apex

  • Automated workflow processes, such as:

  • Workflow rules

  • Assignment rules

  • Approval processes

  • Validation rules


Well webservice can be tricky to debug. Here is a list of items to check

  1. Ensure that the webservice is hosted in internet. Salesforce cannot access a webservice that is in intranet
  2. Since webservice is returning a HTML it can be page like 404 or authentication page. Make sure you are pointing to correct endpoint and using proper authentication
  3. Also if there is firewall make sure you have whitelisted the salesforce IP

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.