function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

SoapException Handling in Apex

I am having a problem calling an external web service. The call is perfect when the return type is identical to WSDL generated Apex class, the trouble starts if the Web service throws a SoapException for a data or business rule value. The exception is caught however am not sure how to process the exception. It seems the return message is truncated in the transition between Soap message to Apex object.
Here is the response for the for the SoapException that is returned from the Web service:
<soap:Envelope xmlns:soap="" xmlns:xsi="" xmlns:xsd="">
         <faultstring>System.Web.Services.Protocols.SoapException: Fault occurred
   at MasterDataWS.GetSertAccountContactMatch(AccountRequest inAccountRequest, ContactRequest inContactRequest)</faultstring>
               <description>Cannot update an existing records without data passed for Last Name.  This is a required field for modifying an object of type: ContactRequest.</description>
When the exception is processed with following codes:
System.debug('====== Exception for GetSertAccountContactMatch '+ex) the response debug statement prints this:
====== Exception for GetSertAccountContactMatch System.CalloutException: Web service callout failed: WebService returned a SOAP Fault: System.Web.Services.Protocols.SoapException: Fault occurred
   at MasterDataWS.GetSertAccountContactMatch(AccountRequest inAccountRequest, ContactRequest inContactRequest) faultcode=soap:Client faultactor=

As you could see detail code and description is not present in the debug print out.
Any response from you this regard is greatly appreciated.
The callout support does not support custom soap fault extensions (and FWIW i don't think that one is valid, your detail child elements are required to be namespaced by the SOAP 1.1 spec).
Hello Simon,
Thank you for your response. I was just wondering is it on the road map?

Best Regards.

It would be nice if the apex developers guide would at least mention these kinds of (important) missing features.





By far the best way to get the docs improved is to use the feedback form at the bottom of every page of the docs.