I am making an apex SOAP callout to an external system. THe connection worked fine last week but suddenly it is failing now due and it gives me this error:

Apex callout Web service callout failed: Unexpected element. Parser was expecting element 'http://schemas.xmlsoap.org/soap/envelope/:Envelope' but found ':h4'

When I tested the webservice throught SOAP UI it works fine and gives me the response. The external system and I are wondering what change has happended and why this error has popped out from no where. Any insights of what I should check when this error comes up?


Check the debug log for the raw CALLOUT_RESPONSE. You might need to do this in a developer edition org to see it.

An h4 in the response suggests you are getting an HTML page back in the response. This usually happens if the server (or proxy) is trying to redirect you to a login or error page.

I've seen cases where the API server rejects certain IP address, which could explain why it works with SOAP UI from your machine but not from Salesforce servers.

  • This error came up suddenly. Does it mean the end system might have modified schema or anything? I get response as NULL. THe external system say they have not made any change – SfdcBat Feb 27 '17 at 19:31
  • 1
    The clue will be in the response that contains the h4 rather than a SOAP envelope. If you can't get the CALLOUT_RESPONSE look for the CALLOUT_REQUEST that contains the SOAP body and then replay that using SOAP UI. – Daniel Ballinger Feb 27 '17 at 19:34
  • I confirmed that there are no IP restriction. – SfdcBat Feb 27 '17 at 20:34
  • I see the CALLOUT_REQUEST which is in a different format since I am calling it through wsdl2apex class. For using it with SOAP UI i would need a xml format correct? And Response I am just get as NULL – SfdcBat Feb 27 '17 at 20:41
  • 1
    Sorry Daniel. The error was because I was using the wrong username ... it was case sensitive and used a wrong case in username. Thus I was getting <H4> access denied </H4> in response – SfdcBat Feb 27 '17 at 21:26

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.