title: Salesforce how to return custom error object
body: <p>I've written the following Apex class as a part of a suite of custom webservices. All have the same problem but this one is the easiest example; if I can solve it for this, I can solve it for the other webservices.</p>
  
  <pre><code>global class WebServiceA4S {
       global class returngetEnquiries {
          public String status {get;set;}
          public String error {get;set;}
          public List&lt;Enquiry__c&gt; results {get;set;}
      }
  
      Webservice static returngetEnquiries  getEnquiries() { 
          returngetEnquiries rtnError = new returngetEnquiries();
          rtnError.status='success';
          rtnError.error = '';
          rtnError.results = new List&lt;Enquiry__c&gt;();
          // id en name
          try {
              list&lt;Enquiry__c&gt; tmp = [Select id,name From Enquiry__c];
              rtnError.results = tmp;
          } 
           catch(Exception e) {
               rtnError.status='error';
               rtnError.error = String.valueof(e);
  
           }
  
  
       return rtnError;
          }
  }
  </code></pre>
  
  <p>Now if I debug the rtnError returned, just before the 'return rtnError', it does show a list of Enquiries so the code works.
  The problem is that if I call the Webservice (via PHP or SOAPUI) the result is empty.
  I use the wsdl from the class, created by salesforce of course.</p>
  
  <p>I also looked at the wsdl and it looks like this:</p>
  
  <pre><code>...
  &lt;xsd:complexType name="returngetEnquiries"&gt;
      &lt;xsd:sequence/&gt;
  &lt;/xsd:complexType&gt;
  &lt;xsd:element name="getEnquiries"&gt;
      &lt;xsd:complexType&gt;
        &lt;xsd:sequence/&gt;
      &lt;/xsd:complexType&gt;
  &lt;/xsd:element&gt;
  &lt;xsd:element name="getEnquiriesResponse"&gt;
   &lt;xsd:complexType&gt;
    &lt;xsd:sequence&gt;
     &lt;xsd:element name="result" type="tns:returngetEnquiries" nillable="true"/&gt;
    &lt;/xsd:sequence&gt;
   &lt;/xsd:complexType&gt;
  &lt;/xsd:element&gt;
  ...
  </code></pre>
  
  <p>It looks like the returngetEnquiries is not defined. I tried to edit it and add the fields as defined in the class, but that doesn't help.</p>