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
Sourav HazraSourav Hazra 

Webservice call out issue - unexpected element

Hi, 

Below is a part of WSDL file (schema part). WSDL2APEX was not able to parse this and throwing an error type missing for resultitem
<xsd:element name="XXXResponse">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element maxOccurs="unbounded" minOccurs="0" name="resultItem"/>
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>
      <xsd:element name="resultItem">
        <xsd:complexType>
          <xsd:sequence>
            <xsd:element maxOccurs="1" name="header" type="xsd:string"/>
            <xsd:element maxOccurs="1" name="text" type="xsd:string"/>
            <xsd:element maxOccurs="1" name="url" type="xsd:string"/>
          </xsd:sequence>
        </xsd:complexType>
      </xsd:element>

I have changed the above part of WSDL like below 

<xsd:element name="XXXResponse">
        <xsd:complexType>
          <xsd:sequence>
     <xsd:element maxOccurs="unbounded" minOccurs="0" name="resultItem">
      <xsd:complexType>
                 <xsd:sequence>
                   <xsd:element maxOccurs="1" name="header" type="xsd:string"/>
                   <xsd:element maxOccurs="1" name="text" type="xsd:string"/>
                   <xsd:element maxOccurs="1" name="url" type="xsd:string"/>
                 </xsd:sequence>
      </xsd:complexType> 
        </xsd:element>
       </xsd:sequence>
     </xsd:complexType>
      </xsd:element>

Now WSDL2APEX parser is able to parse this but while calling out the web service, it encountered an issue - webservice call out failed -unexpected element. 

Wanted to understand if the the modification shown above is correct or there is other way out to change the WSDL. So that it can parsed by WSDL2APEX.
Gaurav NirwalGaurav Nirwal
To avoid this you can simply initialize an Apex map with the query, and use it instead of creating a List. Here it is in action:

view sourceprint?
1
//Fetching all account in map
2
Map<id,account> aMap = new Map<id,account>([Select Id,Name from Account limit 50000]);
3

4
//Creating list of accounts
5
List<account> accList = aMap.values() ;
6

7
//Creating set of ids
8
Set<id> accIds = aMap.keySet() ;