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

WebService Fault Message

Is there a way to pass Fault Message from the WebService created using Apex. If yes, how do we implement it. Or is this part of the return (success) message itself.

Can you please let me know what's the best practice of handling adn returning Exception from the Apex WebService.

Also can we return Object from the Apex WebService to the other calling method which is outside SalesForce


You will get a SOAP Fault element in the body of the message - generally with HTTP you will get 500-599 status code .  The fault element will have the code and an explanatory string.  How you process it depends on how your client environment maps it to your specific programming environment
Can you please explain this in more detail ?
1. I am accepting a stream of XML (String) nto my Apex WebService. If there is an invalid XML, or invalid IDs, how can I send a fault message back to the calling application. Also, how do I include these fault codes as part of the APEX WSDL ?

Thanks for you rreply back.

I am hoping that other Apex gurus will jump in and add specifics here. I am fairly new with the Apex environment but in general with SOAP based web services everything is mapped to a SOAP message.  So now in Apex you would just throw an exception (just like you would with Java) and then it would be mapped to a Fault Element in the SOAP message.  When this SOAP message arrives at the other end, it is mapped to that environment - the message itself is language and API neutral.  Whether you can have the same types depends on the WSDL you use to generate the client code, if you use the Enterprise WSDL you should have access to all the types and looking at the generated code should give you an idea.  If you have done CORBA or J2EE it is similar in a way

Unfortunately, exceptions doesn't seem to be too well documented so you will just have to play with it.

I have not tried this, but I guess if you throw an exception from the apex code, it will get maped to a SOAP fault.