i have to get some data using SOAP api from one org to another .so i generated Enterprise wsdl file of one organization . it contains some fields with specified type as type=xsd:anyType. because apex doesn't support xsd:anyType thats why i changed it to xsd:string .ok it will generate some apex classes .i want to know is it the proper way.for handling anyType or we should do some thing else .Please guideline
[SalesForce] How to handle anyType of wsdl in generating apex classes
Related Solutions
The native version of Wsdl2Apex doesn't support {http://www.w3.org/2001/XMLSchema}anyType
because WebserviceCallout.invoke can't.
By having Account in the methods Arguments and return type Salesforce is going to generate xsd:complexType's for all sorts of supporting types. A number of these will have elements like:
<xsd:element name="NewValue" minOccurs="0" type="xsd:anyType" nillable="true"/>
<xsd:element name="OldValue" minOccurs="0" type="xsd:anyType" nillable="true"/>
Also, generally speaking, wsdl2apex has great difficulty handling sObject types in a WSDL due to the use of <xsd:extension base="tns:sObject">
. It won't generate the required base class fields and WebserviceCallout.invoke doesn't support inheritance.
Since it is now working for you I suspect you have altered the definition of the webservice method so that it no longer takes/returns an Account object.
If that isn't the case, you might like to try the FuseIT SFDC Explorer (Disclosure: The is my current employer). It has an alternative version of Wsdl2Apex that can handle several of these problems. anyType
is still problematic, but you may no care about the types that actually use it.
If you are really keen, there is also the open source version of wsdl2apex, which you code modify as required.
You can use the FuseIT SFDC Explorer to simplify the process and keep the generated Apex to a minimum.
To do this, point the Wsdl2Apex tab at the downloaded Partner API Wsdl.
On the method selection step, uncheck all the methods except the login
one. Set "Exclude" in the drop down at the top of the page that handles how extra classes are processed. This will generate the minimum required Apex.
It will look something like this: (140 lines, 10573 characters)
//Generated by FuseIT WSDL2Apex (http://www.fuseit.com/Solutions/SFDC-Explorer/Help-WSDL-Parser.aspx)
//Methods Included: login
//Methods Excluded: describeSObject, describeSObjects, describeGlobal, describeDataCategoryGroups, describeDataCategoryGroupStructures, describeKnowledgeSettings, describeFlexiPages, describeAppMenu, describeGlobalTheme, describeTheme, describeLayout, describeSoftphoneLayout, describeSearchLayouts, describeSearchScopeOrder, describeCompactLayouts, describeApprovalLayout, describeSoqlListViews, executeListView, describeSObjectListViews, describeTabs, describeAllTabs, describePrimaryCompactLayouts, create, update, upsert, merge, delete, undelete, emptyRecycleBin, retrieve, process, convertLead, logout, invalidateSessions, getDeleted, getUpdated, query, queryAll, queryMore, search, getServerTimestamp, setPassword, resetPassword, getUserInfo, sendEmailMessage, sendEmail, performQuickActions, describeQuickActions, describeAvailableQuickActions, retrieveQuickActionTemplates
// Primary Port Class Name: Soap
public class partnerSoapSforceCom {
public class CallOptions_element {
public String client;
public String defaultNamespace;
private String[] client_type_info = new String[]{'client','urn:partner.soap.sforce.com','string','1','1','true'};
private String[] defaultNamespace_type_info = new String[]{'defaultNamespace','urn:partner.soap.sforce.com','string','1','1','true'};
private String[] apex_schema_type_info = new String[]{'urn:partner.soap.sforce.com','true','false'};
private String[] field_order_type_info = new String[]{'client','defaultNamespace'};
}
public class GetUserInfoResult {
public Boolean accessibilityMode;
public String currencySymbol;
public Integer orgAttachmentFileSizeLimit;
public String orgDefaultCurrencyIsoCode;
public Boolean orgDisallowHtmlAttachments;
public Boolean orgHasPersonAccounts;
public String organizationId;
public Boolean organizationMultiCurrency;
public String organizationName;
public String profileId;
public String roleId;
public Integer sessionSecondsValid;
public String userDefaultCurrencyIsoCode;
public String userEmail;
public String userFullName;
public String userId;
public String userLanguage;
public String userLocale;
public String userName;
public String userTimeZone;
public String userType;
public String userUiSkin;
private String[] accessibilityMode_type_info = new String[]{'accessibilityMode','urn:partner.soap.sforce.com','boolean','1','1','false'};
private String[] currencySymbol_type_info = new String[]{'currencySymbol','urn:partner.soap.sforce.com','string','1','1','true'};
private String[] orgAttachmentFileSizeLimit_type_info = new String[]{'orgAttachmentFileSizeLimit','urn:partner.soap.sforce.com','int','1','1','false'};
private String[] orgDefaultCurrencyIsoCode_type_info = new String[]{'orgDefaultCurrencyIsoCode','urn:partner.soap.sforce.com','string','1','1','true'};
private String[] orgDisallowHtmlAttachments_type_info = new String[]{'orgDisallowHtmlAttachments','urn:partner.soap.sforce.com','boolean','1','1','false'};
private String[] orgHasPersonAccounts_type_info = new String[]{'orgHasPersonAccounts','urn:partner.soap.sforce.com','boolean','1','1','false'};
private String[] organizationId_type_info = new String[]{'organizationId','urn:partner.soap.sforce.com','ID','1','1','false'};
private String[] organizationMultiCurrency_type_info = new String[]{'organizationMultiCurrency','urn:partner.soap.sforce.com','boolean','1','1','false'};
private String[] organizationName_type_info = new String[]{'organizationName','urn:partner.soap.sforce.com','string','1','1','false'};
private String[] profileId_type_info = new String[]{'profileId','urn:partner.soap.sforce.com','ID','1','1','false'};
private String[] roleId_type_info = new String[]{'roleId','urn:partner.soap.sforce.com','ID','1','1','true'};
private String[] sessionSecondsValid_type_info = new String[]{'sessionSecondsValid','urn:partner.soap.sforce.com','int','1','1','false'};
private String[] userDefaultCurrencyIsoCode_type_info = new String[]{'userDefaultCurrencyIsoCode','urn:partner.soap.sforce.com','string','1','1','true'};
private String[] userEmail_type_info = new String[]{'userEmail','urn:partner.soap.sforce.com','string','1','1','false'};
private String[] userFullName_type_info = new String[]{'userFullName','urn:partner.soap.sforce.com','string','1','1','false'};
private String[] userId_type_info = new String[]{'userId','urn:partner.soap.sforce.com','ID','1','1','false'};
private String[] userLanguage_type_info = new String[]{'userLanguage','urn:partner.soap.sforce.com','string','1','1','false'};
private String[] userLocale_type_info = new String[]{'userLocale','urn:partner.soap.sforce.com','string','1','1','false'};
private String[] userName_type_info = new String[]{'userName','urn:partner.soap.sforce.com','string','1','1','false'};
private String[] userTimeZone_type_info = new String[]{'userTimeZone','urn:partner.soap.sforce.com','string','1','1','false'};
private String[] userType_type_info = new String[]{'userType','urn:partner.soap.sforce.com','string','1','1','false'};
private String[] userUiSkin_type_info = new String[]{'userUiSkin','urn:partner.soap.sforce.com','string','1','1','false'};
private String[] apex_schema_type_info = new String[]{'urn:partner.soap.sforce.com','true','false'};
private String[] field_order_type_info = new String[]{'accessibilityMode','currencySymbol','orgAttachmentFileSizeLimit','orgDefaultCurrencyIsoCode','orgDisallowHtmlAttachments','orgHasPersonAccounts','organizationId','organizationMultiCurrency','organizationName','profileId','roleId','sessionSecondsValid','userDefaultCurrencyIsoCode','userEmail','userFullName','userId','userLanguage','userLocale','userName','userTimeZone','userType','userUiSkin'};
}
public class login_element {
public String username;
public String password;
private String[] username_type_info = new String[]{'username','urn:partner.soap.sforce.com','string','1','1','false'};
private String[] password_type_info = new String[]{'password','urn:partner.soap.sforce.com','string','1','1','false'};
private String[] apex_schema_type_info = new String[]{'urn:partner.soap.sforce.com','true','false'};
private String[] field_order_type_info = new String[]{'username','password'};
}
public class loginResponse_element {
public partnerSoapSforceCom.LoginResult result;
private String[] result_type_info = new String[]{'result','urn:partner.soap.sforce.com','LoginResult','1','1','false'};
private String[] apex_schema_type_info = new String[]{'urn:partner.soap.sforce.com','true','false'};
private String[] field_order_type_info = new String[]{'result'};
}
public class LoginResult {
public String metadataServerUrl;
public Boolean passwordExpired;
public Boolean sandbox;
public String serverUrl;
public String sessionId;
public String userId;
public partnerSoapSforceCom.GetUserInfoResult userInfo;
private String[] metadataServerUrl_type_info = new String[]{'metadataServerUrl','urn:partner.soap.sforce.com','string','1','1','true'};
private String[] passwordExpired_type_info = new String[]{'passwordExpired','urn:partner.soap.sforce.com','boolean','1','1','false'};
private String[] sandbox_type_info = new String[]{'sandbox','urn:partner.soap.sforce.com','boolean','1','1','false'};
private String[] serverUrl_type_info = new String[]{'serverUrl','urn:partner.soap.sforce.com','string','1','1','true'};
private String[] sessionId_type_info = new String[]{'sessionId','urn:partner.soap.sforce.com','string','1','1','true'};
private String[] userId_type_info = new String[]{'userId','urn:partner.soap.sforce.com','ID','1','1','true'};
private String[] userInfo_type_info = new String[]{'userInfo','urn:partner.soap.sforce.com','GetUserInfoResult','0','1','false'};
private String[] apex_schema_type_info = new String[]{'urn:partner.soap.sforce.com','true','false'};
private String[] field_order_type_info = new String[]{'metadataServerUrl','passwordExpired','sandbox','serverUrl','sessionId','userId','userInfo'};
}
public class LoginScopeHeader_element {
public String organizationId;
public String portalId;
private String[] organizationId_type_info = new String[]{'organizationId','urn:partner.soap.sforce.com','ID','1','1','false'};
private String[] portalId_type_info = new String[]{'portalId','urn:partner.soap.sforce.com','ID','0','1','false'};
private String[] apex_schema_type_info = new String[]{'urn:partner.soap.sforce.com','true','false'};
private String[] field_order_type_info = new String[]{'organizationId','portalId'};
}
public class SessionHeader_element {
public String sessionId;
private String[] sessionId_type_info = new String[]{'sessionId','urn:partner.soap.sforce.com','string','1','1','false'};
private String[] apex_schema_type_info = new String[]{'urn:partner.soap.sforce.com','true','false'};
private String[] field_order_type_info = new String[]{'sessionId'};
}
public class Soap {
public String endpoint_x = 'https://test.salesforce.com/services/Soap/u/33.0';
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;
public partnerSoapSforceCom.LoginScopeHeader_element LoginScopeHeader;
private String LoginScopeHeader_hns = 'LoginScopeHeader=urn:partner.soap.sforce.com';
public partnerSoapSforceCom.CallOptions_element CallOptions;
private String CallOptions_hns = 'CallOptions=urn:partner.soap.sforce.com';
private String[] ns_map_type_info = new String[]{'urn:sobject.partner.soap.sforce.com','sobjectPartnerSoapSforceCom','urn:partner.soap.sforce.com','partnerSoapSforceCom','urn:fault.partner.soap.sforce.com','faultPartnerSoapSforceCom'};
public partnerSoapSforceCom.LoginResult login(String username,String password) {
partnerSoapSforceCom.login_element request_x = new partnerSoapSforceCom.login_element();
partnerSoapSforceCom.loginResponse_element response_x;
request_x.username = username;
request_x.password = password;
Map<String, partnerSoapSforceCom.loginResponse_element> response_map_x = new Map<String, partnerSoapSforceCom.loginResponse_element>();
response_map_x.put('response_x', response_x);
WebServiceCallout.invoke(
this,
request_x,
response_map_x,
new String[]{endpoint_x,
'',
'urn:partner.soap.sforce.com',
'login',
'urn:partner.soap.sforce.com',
'loginResponse',
'partnerSoapSforceCom.loginResponse_element'}
);
response_x = response_map_x.get('response_x');
return response_x.result;
}
}
}
Then you can use the securely stored Salesforce credentials to establish the session.
partnerSoapSforceCom.Soap partner = new partnerSoapSforceCom.Soap();
partnerSoapSforceCom.LoginResult lr = partner.login('user@example.com', 'SomePassword' + 'SomeSecurityToken');
System.debug(lr.sessionId);
Don't forget to add the required target URL in the remote site settings.
Best Answer
The Enterprise and Partner APIs are intended for usage outside of Salesforce rather than integrating two Salesforce Orgs together. They are typically consumed by languages like Java, .NET, PHP, Ruby, ...
As you found, anyType is not supported by Wsdl2Apex. See Supported WSDL Features:
So in earlier versions anyType was mapped to string. You can certainly change it in the WSDL element types to get WSDL2Apex to import it.
It appears to only be used on the NewValue and OldValue elements on History Types. E.g. from AccountHistory.
If you aren't going to be working with these History sObjects then you aren't likely to have any issues with the change.
Alternatives: