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
Bidun TummalaBidun Tummala 

How to return SOAP Fault.

If I create a web service in Apex to be called from outside Salesforce, can I send a SOAP fault response back to the caller?

 

Webservice static Product_Return ContactMethod(String hlpid, List<Product_Input> ProductIn)
{
    
   
    try{
        Account acnt = [SELECT Id,LP_ID_Hash__c,State_Calling_Rule__r.Mortgage_InFootPrint__c from Account WHERE Legal_Person_Id__c =: hlpid LIMIT 1];
        ..

 

}Catch(Exception e){

}

 

Product return is a Object that i will be returning. How would i return a proper SOAP Fault message if the query returns no results.

 

Regards,

Bidun

joshbirkjoshbirk
Bidun TummalaBidun Tummala

Thank you very much. That really helped.  I used SOAP UI to see the responce please check  output.

 

SOAP UI Result:

 

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Body>
      <soapenv:Fault>
         <faultcode>soapenv:Client</faultcode>
         <faultstring>ICG_CrossSellWSDL_RecomendProdObj.SOAP2Exception: This is my SOAP UI Fault message Class.ICG_MyClass.ContactMethod: line 189, column 1</faultstring>
      </soapenv:Fault>
   </soapenv:Body>
</soapenv:Envelope>

 

Code:

Catch(Exception e){

/* Line 189 */  throw new SOAP2Exception('This is my SOAP UI Fault message');

 

Is there a way where i can stop this responce 'Class.ICG_MyClass.ContactMethod: line 189, column 1'

 

Thank you very much,

 

Regards,

Bidun

 

DurgaDurga

I am also facing the same problem.  The custom Apex exception is being translated into SOAP fault but it comes with line numbers and stack output.  Is there any way we can prevent whole exception stack from appearing in the fault message?  We just wanted to have only message show up in the fault.

Felix LopezFelix Lopez
5 years later I face the same requirement, any update on this? :P