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
prufrockprufrock 

SoapException Handling in Apex

Hello,
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="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <soap:Body>
      <soap:Fault>
         <faultcode>soap:Client</faultcode>
         <faultstring>System.Web.Services.Protocols.SoapException: Fault occurred
   at MasterDataWS.GetSertAccountContactMatch(AccountRequest inAccountRequest, ContactRequest inContactRequest)</faultstring>
         <detail>
            <fault>
               <code>10003</code>
               <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>
            </fault>
         </detail>
      </soap:Fault>
   </soap:Body>
</soap:Envelope>
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.
Regards.
SuperfellSuperfell
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).
prufrockprufrock
Hello Simon,
Thank you for your response. I was just wondering is it on the road map?

Best Regards.
etoeto

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

 

regards

 

 

SuperfellSuperfell
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.