Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Salesforce by (11.9k points)

I am having trouble with wsdl2apex code generation, mainly due to the use of xs:import namespaceand xs:extension in my WSDL.

In particular, I am seeing the error System.CalloutException: Web service callout failed: Unable to parse callout response. Apex type not found for element . . .. The raw SOAP response returned by the web service looks as I would expect.

I would like to modify the generated Apex classes to work around this issue, as server-side changes to the web service is not an option.

The SOAP response looks like the below:

<ns:getAccountsResponse>

 <ns:return xsi:type="ax1:AccountReturn">

  <ax2:successful>true</ax2:successful>

  <ax2:transactionId>1000</ax2:transactionId>

  <ax1:Accounts xsi:type="ax1:Account">

And the WSDL looks like this for the ax1 target namespace:

<xs:complexType name="AccountReturn">

 <xs:complexContent>

  <xs:extension base="ax100:BaseReturnObject">

   <xs:sequence>

    <xs:element maxOccurs="unbounded" minOccurs="0" name="Accounts" nillable="true" type="ax1:Account"/>

   </xs:sequence>

  </xs:extension>

 </xs:complexContent>

</xs:complexType>

And for the ax2 target namespace:

<xs:complexType name="BaseReturnObject">

 <xs:sequence>

  <xs:element minOccurs="0" name="successful" type="xs:boolean"/>

  <xs:element minOccurs="0" name="transactionId" nillable="true" type="xs:integer"/>

 </xs:sequence>

</xs:complexType>

The generated Apex Class which maps to AccountReturn only contains the fields for Accounts in ax1, but not the BaseReturnObject fields in ax2, since the wsdl2apex generation does not respect the use of xs:extension or the importing of namespaces (based on my research).

Is there any way to modify the Apex Class to make this work? I tried adding the fields from BaseReturnObject to AccountReturn, and modifying field_order_type_info. However, it appears that apex_schema_type_info can only point to one namespace, and this may be the reason that the parsing of the callout response is still failing.

1 Answer

0 votes
by (32.1k points)
edited by

I have built a tool for automating the creation of the Apex classes. It covers support for xs:extension and xs:import (among other things).

In the case of an ex:extension, the tool will pull the specific fields from the base class into the subclass and correctly configure the _type_info members.

You can get it for free - FuseIT SFDC Explorer. Currently in only runs directly in Windows. I've had reports of people running it successfully using Wine. (Disclosure: I work for the company that releases this tool).

Accidentally, the salesforce.stackexchange.com site is a great place to ask Salesforce-specific questions.

To learn in-depth about Salesforce, sign up for an industry-based Salesforce Certification!

Browse Categories

...