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
tekane4tekane4 

WSDL Apex class problem - AnyType

Hey

 

Iam trying to connect Force.com with some WSDL serivice. But I have problem since that service uses AnyType types. I saw that Force WSDL Apex does not supports them. When I import WSDL file it creates this class and makes an error because AnyType is reserved.

 

Error: Identifier name is reserved: anyType at 92:25

 

public class ArrayOfAnyType {
public String[] anyType;
private String[] anyType_type_info = new String[ {'anyType','http://www.w3.org/2001/XMLSchema','string','0','-1','true'};
private String[] apex_schema_type_info = new String[]{'http://partnerURL.com','true','false'};
private String[] field_order_type_info = new String[]{'anyType'};
}

 

Is there any way around, without changing original WSDL service on partner side?

 

Thanks a lot!

 

Warm regards to all!

 

Best Answer chosen by Admin (Salesforce Developers) 
Jerun JoseJerun Jose
The apex variables names are not really the element names in the soap request.

In the element definition

public class ArrayOfAnyType {
public String[] MyAnyType;
private String[] MyAnyType_type_info = new String[ {'anyType','http://www.w3.org/2001/XMLSchema','string','0','-1','true'};
private String[] apex_schema_type_info = new String[]{'http://partnerURL.com','true','false'};
private String[] field_order_type_info = new String[]{'MyAnyType'};
}


The line
private String[] MyAnyType_type_info = new String[ {'anyType','http://www.w3.org/2001/XMLSchema','string','0','-1','true'};
defines the soap element name and type for the variable MyAnyType.

You probably did not change the line
private String[] field_order_type_info = new String[]{'MyAnyType'};
when you modified the apex class.

All Answers

Jerun JoseJerun Jose
you will need to rename the variables generated to save your class.

public class ArrayOfAnyType {
public String[] MyAnyType;
private String[] MyAnyType_type_info = new String[ {'anyType','http://www.w3.org/2001/XMLSchema','string','0','-1','true'};
private String[] apex_schema_type_info = new String[]{'http://partnerURL.com','true','false'};
private String[] field_order_type_info = new String[]{'MyAnyType'};
}
tekane4tekane4

Thank you for replay.

 

But I already tried that... Iam getting error when executing with VisualForce:

 

Web service callout failed: Unable to parse callout response. Apex type not found for element http://partnerSITE.com/=anyType

 

The problem is that the name from partner site is like that:

 

<s:complexType name="ArrayOfAnyType">
<s:sequence>
<s:element minOccurs="0" maxOccurs="unbounded" name="anyType" nillable="true"/>
</s:sequence>
</s:complexType>
 
How could I rename that variable in apex class?
 
 
Jerun JoseJerun Jose
The apex variables names are not really the element names in the soap request.

In the element definition

public class ArrayOfAnyType {
public String[] MyAnyType;
private String[] MyAnyType_type_info = new String[ {'anyType','http://www.w3.org/2001/XMLSchema','string','0','-1','true'};
private String[] apex_schema_type_info = new String[]{'http://partnerURL.com','true','false'};
private String[] field_order_type_info = new String[]{'MyAnyType'};
}


The line
private String[] MyAnyType_type_info = new String[ {'anyType','http://www.w3.org/2001/XMLSchema','string','0','-1','true'};
defines the soap element name and type for the variable MyAnyType.

You probably did not change the line
private String[] field_order_type_info = new String[]{'MyAnyType'};
when you modified the apex class.
This was selected as the best answer
tekane4tekane4

Thanks! It worked :)

tekane4tekane4

One more thing..

 

The WSDL repsone give me an array of Items.

 

Main

|- one

| - - - subitem1

| - - - subitem2

|- two

| - - - subitem1

|- three

 

Now Iam able to get just ONE with subitem1. Iam dont know how to display the rest of them.

 

Any clue?

 

This is my code:

 

public class ArrayOfAnyType {

public String xmlNumber;
public String xmlStatus;
public String xmlTitle;

private String[] xmlNumber_type_info = new String[]{'xmlNumber','http://source.com','string','0','1','false'};
private String[] xmlStatus_type_info = new String[]{'xmlStatus','http://source.com','xmlStatus','0','1','false'};
private String[] xmlTitle_type_info = new String[]{'xmlNaziv','http://source.com','xmlTitle','0','1','false'};

public String[] MyAnyType;
private String[] MyAnyType_type_info = new String[]{'anyType','http://www.w3.org/2001/XMLSchema','string','0','-1','true'};
private String[] apex_schema_type_info = new String[]{'http://source.com/','true','false'};
private String[] field_order_type_info = new String[]{'MyAnyType'};

}

Jerun JoseJerun Jose
So the response is an element 'main' which has an array of 'numbers' .. and each number is an array of 'subitems' . Am I right?

In that case, you will need to modify the wsdl apex class to setup this structure of response.
tekane4tekane4

Hello!

 

Here is the XML response structure and my Apex class. With this class Iam able to get just one item of anytype xmlPeople and one anytype AddInfosType.

 

What should I fix that it will work for all?

 

Thank you very much. I realy appreciate your contribution and help.

 

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<searchResponse xmlns="http://Partner.com/">
<searchResult>
<anyType xsi:type="xmlPeople">
<xmlNumber>12341</xmlNumber>
<xmlSubNumber>5235141</xmlSubNumber>
<xmlStatus>70</xmlStatus>
<xmlTitle>Some Title</xmlTitle>
<xmlAddress>Some address</xmlAddress>
<xmlPeopleFlag>true</xmlPeopleFlag>
<xmlOpFlag>true</xmlOpFlag>
<xmlDateReg xsi:nil="true"/>
<xmlDType>124124</xmlDType>
<xmlLocation>08</xmlLocation>
<xmlAddInfos>
<anyType xsi:type="xmlAddInfosType">
<xmlInfoNum>51521412-2421</xmlInfoNum>
<xmlInfoType>84</xmlInfoType>
<xmlInfoTypeName>Some type name</xmlInfoTypeName>
<xmlInfoDateO>2002-04-10T00:00:00</xmlInfoDateO>
<xmlInfoDateL>2010-06-30T00:00:00</xmlInfoDateL>
<xmlInfoFlag>false</xmlInfoFlag>
<xmlInfoDateC>2099-12-31T23:59:59</xmlInfoDateC>
</anyType>
</xmlAddInfos>
</anyType>
<anyType xsi:type="xmlPeople">
<xmlNumber>41241412</xmlNumber>
<xmlSubNumber>4635235</xmlSubNumber>
<xmlStatus>80</xmlStatus>
<xmlTitle>
Some title2
</xmlTitle>
<xmlAddress>Some address2</xmlAddress>
<xmlPeopleFlag>true</xmlPeopleFlag>
<xmlOpFlag>true</xmlOpFlag>
<xmlDateReg>2007-01-29T00:00:00</xmlDateReg>
<xmlDType>4142</xmlDType>
<xmlLocation>11</xmlLocation>
<xmlAddInfos>
<anyType xsi:type="xmlAddInfosType">
<xmlInfoNum>51242412-2144</xmlInfoNum>
<xmlInfoType>84</xmlInfoType>
<xmlInfoTypeName>Some info typename2</xmlInfoTypeName>
<xmlInfoDateO>2007-01-10T00:00:00</xmlInfoDateO>
<xmlInfoDateL>2012-09-21T00:00:00</xmlInfoDateL>
<xmlInfoFlag>false</xmlInfoFlag>
<xmlInfoDateC>2099-12-31T23:59:59</xmlInfoDateC>
</anyType>
<anyType xsi:type="xmlAddInfosType">
<xmlInfoNum>24141241-2414</xmlInfoNum>
<xmlInfoType>84</xmlInfoType>
<xmlInfoTypeName>Some info2 typename3</xmlInfoTypeName>
<xmlInfoDateO>2012-09-21T00:00:00</xmlInfoDateO>
<xmlInfoDateL>2012-09-21T00:00:00</xmlInfoDateL>
<xmlInfoFlag>false</xmlInfoFlag>
<xmlInfoDateC>2099-12-31T23:59:59</xmlInfoDateC>
</anyType>
</xmlAddInfos>
</anyType>
</searchResult>
</searchResponse>
</soap:Body>
</soap:Envelope>


//Generated by wsdl2apex

public with sharing class mytestclass {

public SearchSOAP i{get;set;}
public arrayofanytype peoples{get;set;}
public object[] o = new List<object>();
public xmlPeople z{get;set;}
public String peopleNum{get;set;}
public String peopleSubNum{get;set;}
public String peopleTitle{get;set;}
public mytestclass() {

i = new SearchSOAP();
peoples = i.Search(ApexPages.currentPage().getParameters().get('search'));
peopleNum = peoples.xmlNumber;
peopleSubNum = peoples.xmlSubNumber;
peopleTitle = peoples.xmlTitle;
}

public class xmlAddInfosType {

public String xmlInfoNum;
public String xmlInfoType;
public String xmlInfoTypeName;
public DateTime xmlInfoDateO;
public DateTime xmlInfoDateL;
public Boolean xmlInfoFlag;
public DateTime xmlInfoDateC;
private String[] xmlInfoNum_type_info = new String[]{'xmlInfoNum','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
private String[] xmlInfoType_type_info = new String[]{'xmlInfoType','http://microsoft.com/wsdl/types/','char','1','1','false'};
private String[] xmlInfoTypeName_type_info = new String[]{'xmlInfoTypeName','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
private String[] xmlInfoDateO_type_info = new String[]{'xmlInfoDateO','http://www.w3.org/2001/XMLSchema','dateTime','1','1','false'};
private String[] xmlInfoDateL_type_info = new String[]{'xmlInfoDateL','http://www.w3.org/2001/XMLSchema','dateTime','1','1','false'};
private String[] xmlInfoFlag_type_info = new String[]{'xmlInfoFlag','http://www.w3.org/2001/XMLSchema','boolean','1','1','false'};
private String[] xmlInfoDateC_type_info = new String[]{'xmlInfoDateC','http://www.w3.org/2001/XMLSchema','dateTime','1','1','false'};
private String[] apex_schema_type_info = new String[]{'http://Partner.com/','true','false'};
private String[] field_order_type_info = new String[]{'xmlInfoNum','xmlInfoType','xmlInfoTypeName','xmlInfoDateO','xmlInfoDateL','xmlInfoFlag','xmlInfoDateC'};
}
public class xmlPeople{

public String xmlNumber;
public String xmlSubNumber;
public String xmlStatus;
public String xmlTitle;
public String xmlAddress;
public Boolean xmlPeopleFlag;
public Boolean xmlOpFlag;
public DateTime xmlDateReg;
public String xmlDType;
public String xmlLocation;
public mytestclass.arrayofanytype xmlAddInfos;

private String[] xmlNumber_type_info = new String[]{'xmlNumber','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
private String[] xmlSubNumber_type_info = new String[]{'xmlSubNumber','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
public String[] xmlStatus_type_info = new String[]{'xmlStatus','http://microsoft.com/wsdl/types/','char','1','1','false'};
private String[] xmlTitle_type_info = new String[]{'xmlTitle','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
private String[] xmlAddress_type_info = new String[]{'xmlAddress','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
private String[] xmlPeopleFlag_type_info = new String[]{'xmlPeopleFlag','http://www.w3.org/2001/XMLSchema','boolean','1','1','false'};
private String[] xmlOpFlag_type_info = new String[]{'xmlOpFlag','http://www.w3.org/2001/XMLSchema','boolean','1','1','false'};
private String[] xmlDateReg_type_info = new String[]{'xmlDateReg','http://www.w3.org/2001/XMLSchema','dateTime','1','1','true'};
private String[] xmlDType_type_info = new String[]{'xmlDType','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
private String[] xmlLocation_type_info = new String[]{'xmlLocation','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
private String[] xmlAddInfos_type_info = new String[]{'xmlAddInfos','http://Partner.com/','arrayofanytype','0','1','false'};
private String[] apex_schema_type_info = new String[]{'http://Partner.com/','true','false'};
private String[] field_order_type_info = new String[]{'xmlNumber','xmlSubNumber','xmlStatus','xmlTitle','xmlAddress','xmlPeopleFlag','xmlOpFlag','xmlDateReg','xmlDType','xmlLocation','xmlAddInfos'};
}
public class SearchSOAP {
public String endpoint_x = 'http://Partner.com/Iskalnik.asmx';
public Map<String,String> inputHttpHeaders_x;
public Map<String,String> outputHttpHeaders_x;
public String clientCertName_x;
public String clientCert_x;
public String clientCertPasswd_x;
public Integer timeout_x;
private String[] ns_map_type_info = new String[]{'http://Partner.com/', 'mytestclass', 'http://microsoft.com/wsdl/types/', 'mytestclass'};


public mytestclass.arrayofanytype Search(String search_string) {

mytestclass.Search_element request_x = new mytestclass.Search_element();
mytestclass.searchResponse_element response_x;
request_x.search_string = search_string;
Map<String, mytestclass.searchResponse_element> response_map_x = new Map<String, mytestclass.searchResponse_element>();
response_map_x.put('response_x', response_x);
WebServiceCallout.invoke(
this,
request_x,
response_map_x,
new String[]{endpoint_x,
'http://Partner.com/Search',
'http://Partner.com/',
'Search',
'http://Partner.com/',
'searchResponse',
'mytestclass.searchResponse_element'}
);

response_x = response_map_x.get('response_x');
return response_x.searchResult;

}
}
public class Search_element {
public String search_string;
private String[] search_string_type_info = new String[]{'search_string','http://www.w3.org/2001/XMLSchema','string','0','1','false'};
private String[] apex_schema_type_info = new String[]{'http://Partner.com/','true','false'};
private String[] field_order_type_info = new String[]{'search_string'};
}

public class ArrayOfAnyType {

public String xmlNumber;
public String xmlSubNumber;
public String xmlStatus;
public String xmlTitle;

private String[] xmlNumber_type_info = new String[]{'xmlNumber','http://Partner.com','string','0','1','false'};
private String[] xmlSubNumber_type_info = new String[]{'xmlSubNumber','http://Partner.com','xmlSubNumber','0','1','false'};
private String[] xmlStatus_type_info = new String[]{'xmlStatus','http://Partner.com','xmlStatus','0','1','false'};
private String[] xmlTitle_type_info = new String[]{'xmlTitle','http://Partner.com','xmlTitle','0','1','false'};

public String xmlAddress;
private String[] xmlAddress_type_info = new String[]{'xmlAddress','http://Partner.com','xmlAddress','0','1','false'};

public String xmlPeopleFlag;
private String[] xmlPeopleFlag_type_info = new String[]{'xmlPeopleFlag','http://Partner.com','xmlPeopleFlag','0','1','false'};

public String xmlOpFlag;
private String[] xmlOpFlag_type_info = new String[]{'xmlOpFlag','http://Partner.com','xmlOpFlag','0','1','false'};

public String xmlDateReg;
private String[] xmlDateReg_type_info = new String[]{'xmlDateReg','http://Partner.com','xmlDateReg','0','1','false'};

public String xmlDType;
private String[] xmlDType_type_info = new String[]{'xmlDType','http://Partner.com','xmlDType','0','1','false'};

public String xmlLocation;
private String[] xmlLocation_type_info = new String[]{'xmlLocation','http://Partner.com','xmlLocation','0','1','false'};

public arrayofanytype xmlAddInfos;
private String[] xmlAddInfos_type_info = new String[]{'xmlAddInfos','http://Partner.com','xmlAddInfos','0','1','false'};

public String xmlInfoNum;
private String[] xmlInfoNum_type_info = new String[]{'xmlInfoNum','http://Partner.com','xmlInfoNum','0','1','false'};

public String xmlInfoType;
private String[] xmlInfoType_type_info = new String[]{'xmlInfoType','http://Partner.com','xmlInfoType','0','1','false'};

public String xmlInfoTypeName;
private String[] xmlInfoTypeName_type_info = new String[]{'xmlInfoTypeName','http://Partner.com','xmlInfoTypeName','0','1','false'};

public String xmlInfoDateO;
private String[] xmlInfoDateO_type_info = new String[]{'xmlInfoDateO','http://Partner.com','xmlInfoDateO','0','1','false'};

public String xmlInfoDateL;
private String[] xmlInfoDateL_type_info = new String[]{'xmlInfoDateL','http://Partner.com','xmlInfoDateL','0','1','false'};

public String xmlInfoFlag;
private String[] xmlInfoFlag_type_info = new String[]{'xmlInfoFlag','http://Partner.com','xmlInfoFlag','0','1','false'};

public String xmlInfoDateC;
private String[] xmlInfoDateC_type_info = new String[]{'xmlInfoDateC','http://Partner.com','xmlInfoDateC','0','1','false'};

List<String> MyAnyType = new List<String>();

private String[] MyAnyType_type_info = new String[]{'anyType','http://www.w3.org/2001/XMLSchema','string','0','-1','true'};
private String[] apex_schema_type_info = new String[]{'http://Partner.com/','true','false'};
private String[] field_order_type_info = new String[]{'MyAnyType'};

}


public class searchResponse_element {
public mytestclass.arrayofanytype searchResult;
private String[] searchResult_type_info = new String[]{'searchResult','http://Partner.com/','arrayofanytype','0','1','false'};
private String[] apex_schema_type_info = new String[]{'http://Partner.com/','true','false'};
private String[] field_order_type_info = new String[]{'searchResult'};

}
}

 

 

Jerun JoseJerun Jose
I can see a fair bit of inconsistencies with the wsdl class and the xml data. Have you made any other alterations to the autogenerated class besides the anytype change. The reason I am asking this is because the ArrayOfAnytype class typically has an 'array' of a particular type. Also, I see that in the response, there is a parent as well as a child element which has the name of 'anytype' which could have caused issues with the wsdl to apex class. If that is the case, we might have to manufacture the class ourselves as the wsdl to apex class will not suffice.
Jerun JoseJerun Jose