This is an older problem that I had back in 2011 but got no further than promoting the Salesforce Idea: SOAPFault Information for Apex. It came up again today with users of a managed package wanting better error messages when a web service callout fails.

The Problem

I'm calling a web service that will return a Fault and FaultMessage(s) if there is an issue with the request. E.g.

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
      <faultstring xml:lang="en-US">The creator of this fault did not specify a Reason.</faultstring>
        <DataAccessFault xmlns="http://www.example.com/api" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
          <FaultMessges xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
            <a:string>Validation Error(s) occurred during Save.</a:string>
            <a:string>Meaningful error message appears here</a:string>

When this gets handled by Apex it gets turned into a CalloutException:

Cause: null
Message: Web service callout failed: WebService returned a SOAP Fault: The creator of this fault did not specify a Reason. faultcode=s:Client faultactor=

The issue I have is that the getMessage() method doesn't return the entire SOAP reponse. It has been truncated before the useful information appears.

Is there some way to recover the entire response from the CalloutException in code so I can give a meaning error back to the user?

Currently I need to resort to capturing the Outbound SOAP message and response using the third party tool like soapUI. While this works for debugging, it doesn't help the users during normal usage. Another option during development is to pull the Callout request and response from the debug log. Again, not very useful for giving users meaningful responses in the managed package.


1 Answer 1


I have seen this done in two different ways

  1. on callout failure, use apex to recreate your outbound xml, send it using httpRequest and parse the response xml to get your error message

  2. add an 'error' string field to the response class. You then do your webservice call to an intermediate layer which hides these exceptions and always returns to salesforce a 'valid' response.

both of which are just workarounds to salesforce limitations

  • Can you please provide more details regarding your workarounds? Thank you.
    – user17517
    Mar 2, 2015 at 16:19
  • how can I work with the second option? Can you please elaborate it?
    – user27148
    Dec 15, 2015 at 10:36

You must log in to answer this question.

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