1

Wsdl2Apex Generated Class:

public class wwwTheyukicompanyCom1 {
    public class ProcessSalesInvoicesResponse_element {
        public wwwTheyukicompanyCom1.ProcessSalesInvoicesResult_element ProcessSalesInvoicesResult;
        private String[] ProcessSalesInvoicesResult_type_info = new String[]{'ProcessSalesInvoicesResult','http://www.theyukicompany.com/',null,'0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://www.theyukicompany.com/','true','false'};
        private String[] field_order_type_info = new String[]{'ProcessSalesInvoicesResult'};
    }
    public class ProcessSalesInvoices_element {
        public String sessionId;
        public String administrationId;
        public wwwTheyukicompanyCom1.xmlDoc_element xmlDoc;
        private String[] sessionId_type_info = new String[]{'sessionId','http://www.theyukicompany.com/',null,'0','1','false'};
        private String[] administrationId_type_info = new String[]{'administrationId','http://www.theyukicompany.com/',null,'0','1','false'};
        private String[] xmlDoc_type_info = new String[]{'xmlDoc','http://www.theyukicompany.com/',null,'0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://www.theyukicompany.com/','true','false'};
        private String[] field_order_type_info = new String[]{'sessionId','administrationId','xmlDoc'};
    }    
    public class ProcessSalesInvoicesResult_element {
        private String[] apex_schema_type_info = new String[]{'http://www.theyukicompany.com/','true','false'};
        private String[] field_order_type_info = new String[]{};
    }    
    public class xmlDoc_element {
        private String[] apex_schema_type_info = new String[]{'http://www.theyukicompany.com/','true','false'};
        private String[] field_order_type_info = new String[]{};
    }
    public class SalesSoap {
        public String endpoint_x = 'http://api.yukiworks.nl/ws/Sales.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://www.theyukicompany.com/', 'wwwTheyukicompanyCom1'};
        public wwwTheyukicompanyCom1.ProcessSalesInvoicesResult_element ProcessSalesInvoices(String sessionId,String administrationId,wwwTheyukicompanyCom1.xmlDoc_element xmlDoc) {
            wwwTheyukicompanyCom1.ProcessSalesInvoices_element request_x = new wwwTheyukicompanyCom1.ProcessSalesInvoices_element();
            request_x.sessionId = sessionId;
            request_x.administrationId = administrationId;
            request_x.xmlDoc = xmlDoc;
            wwwTheyukicompanyCom1.ProcessSalesInvoicesResponse_element response_x;
            Map<String, wwwTheyukicompanyCom1.ProcessSalesInvoicesResponse_element> response_map_x = new Map<String, wwwTheyukicompanyCom1.ProcessSalesInvoicesResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              'http://www.theyukicompany.com/ProcessSalesInvoices',
              'http://www.theyukicompany.com/',
              'ProcessSalesInvoices',
              'http://www.theyukicompany.com/',
              'ProcessSalesInvoicesResponse',
              'wwwTheyukicompanyCom1.ProcessSalesInvoicesResponse_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.ProcessSalesInvoicesResult;
        }
    }
}

I am trying to call ProcessSalesInvoices() in SalesSoap class using below from anonymous window:

wwwTheyukicompanyCom1.SalesSoap s = new wwwTheyukicompanyCom1.SalesSoap();
wwwTheyukicompanyCom1.xmlDoc_element xmldoc = new wwwTheyukicompanyCom1.xmlDoc_element();
s.ProcessSalesInvoices('','',xmldoc);

Executing above gives the error: Value cannot be null for parameter "xmlDoc"

In above wsdl2apex generated class, 'xmldoc_element' class have only private variables in it. So I changed the class as below for testing:

public class xmlDoc_element {
    private String[] apex_schema_type_info = new String[]{'http://www.theyukicompany.com/','true','false'};
    private String[] field_order_type_info = new String[]{'*'};
}

running the same above code from anonymous window now gives the error: System.CalloutException: Web service callout failed: Unable to find field '*' found in fieldOrder

How can I identify and fix the exact issue?

1 Answer 1

1

The problem with xmlDoc is that it originates from this part of the WSDL.

<s:element name="ProcessSalesInvoices">
  <s:complexType>
    <s:sequence>
      <s:element minOccurs="0" maxOccurs="1" name="sessionId" type="s:string"/>
      <s:element minOccurs="0" maxOccurs="1" name="administrationId" type="s:string"/>
      <s:element minOccurs="0" maxOccurs="1" name="xmlDoc">
        <s:complexType mixed="true">
          <s:sequence>
            <s:any/>
          </s:sequence>
        </s:complexType>
      </s:element>
    </s:sequence>
  </s:complexType>
</s:element>

Basically, it is using <xsd:any> (from http://www.w3.org/2001/XMLSchema).

WebServiceCallout.invoke doesn't support this, so you need to work around it.

The Salesforce datatype anyType is not supported in WSDLs used to generate Apex code that is saved using API version 15.0 and later. For code saved using API version 14.0 and earlier, anyType is mapped to String. Source

When I encounter <xsd:any> I'll convert it to either a string or List<DOM.XmlNode>. It isn't perfect, but will at least give you something to start from.

Another way to work around it is to generate the raw HTTP request and parse the response.

E.g. Where you would use wwwTheyukicompanyCom.SalesSoap.ProcessSalesInvoices_Http()

//Generated by FuseIT WSDL2Apex (http://www.fuseit.com/Solutions/SFDC-Explorer/Help-WSDL-Parser.aspx)
//Warning: '<xsd:any>' element type has been changed to dataType List<DOM.XmlNode> called anyElement
//Methods Included: ProcessSalesInvoices
//Methods Excluded: SalesInvoiceSchemaPath, Authenticate, AuthenticateByUserName, Domains, Companies, AdministrationID, Administrations, GetCurrentDomain, SetCurrentDomain, Language
// Primary Port Class Name: SalesSoap   
public class wwwTheyukicompanyCom {
    public class ProcessSalesInvoices_element {
        public String sessionId;
        public String administrationId;
        public wwwTheyukicompanyCom.ProcessSalesInvoices_xmlDoc_element xmlDoc;
        private String[] sessionId_type_info = new String[]{'sessionId','http://www.theyukicompany.com/','string','0','1','false'};
        private String[] administrationId_type_info = new String[]{'administrationId','http://www.theyukicompany.com/','string','0','1','false'};
        private String[] xmlDoc_type_info = new String[]{'xmlDoc','http://www.theyukicompany.com/','','0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://www.theyukicompany.com/','true','false'};
        private String[] field_order_type_info = new String[]{'sessionId','administrationId','xmlDoc'};
        public ProcessSalesInvoices_element(){
        }
        public ProcessSalesInvoices_element(String sessionId,String administrationId,wwwTheyukicompanyCom.ProcessSalesInvoices_xmlDoc_element xmlDoc){
            this.sessionId = sessionId;
            this.administrationId = administrationId;
            this.xmlDoc = xmlDoc;
        }
        public void populateXmlNode(Dom.XmlNode outerNode){

            //System.assertEquals('ProcessSalesInvoices', outerNode.getName());
            Dom.XmlNode sessionIdNode = outerNode.addChildElement('sessionId', 'http://www.theyukicompany.com/', '');
            sessionIdNode.addTextNode((this.sessionId == null) ? '' : this.sessionId);
            Dom.XmlNode administrationIdNode = outerNode.addChildElement('administrationId', 'http://www.theyukicompany.com/', '');
            administrationIdNode.addTextNode((this.administrationId == null) ? '' : this.administrationId);

            wwwTheyukicompanyCom.ProcessSalesInvoices_xmlDoc_element xmlDocObj = this.xmlDoc;
            Dom.XmlNode xmlDocNode = outerNode.addChildElement('xmlDoc', 'http://www.theyukicompany.com/', '');
            if(xmlDocObj != null){
                xmlDocObj.populateXmlNode(xmlDocNode);
            }
        }
    }

    //Warning: '<xsd:any>' element type has been changed to dataType List<DOM.XmlNode> called anyElement
    public class ProcessSalesInvoices_xmlDoc_element {
        public List<DOM.XmlNode> anyElement;
        private String[] anyElement_type_info = new String[]{'anyElement','http://www.theyukicompany.com/','List<DOM.XmlNode>','0','1','true'};
        private String[] apex_schema_type_info = new String[]{'http://www.theyukicompany.com/','true','false'};
        private String[] field_order_type_info = new String[]{'anyElement'};
        public ProcessSalesInvoices_xmlDoc_element(){
        }
        public ProcessSalesInvoices_xmlDoc_element(DOM.XmlNode responseNode){
            Set<DOM.XmlNode> nodesParsed = new Set<DOM.XmlNode>();

            this.anyElement = new List<DOM.XmlNode>();
            for(DOM.XmlNode childNode: responseNode.getChildElements()){
                if(!nodesParsed.contains(childNode)){
                    this.anyElement.add(childNode);
                }
            }
            //System.debug(this.anyElement);            
        }
        public void populateXmlNode(Dom.XmlNode outerNode){

            List<DOM.XmlNode> anyElementObj = this.anyElement;
            for(DOM.XmlNode anyNode: this.anyElement){
                Dom.XmlNode anyElementNode = outerNode.addChildElement(anyNode.getName(), anyNode.getNamespace(), ''); 
            }
        }
    }
    public class ProcessSalesInvoicesResponse_element {
        public wwwTheyukicompanyCom.ProcessSalesInvoicesResponse_ProcessSalesInvoicesResult_element ProcessSalesInvoicesResult;
        private String[] ProcessSalesInvoicesResult_type_info = new String[]{'ProcessSalesInvoicesResult','http://www.theyukicompany.com/','','0','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://www.theyukicompany.com/','true','false'};
        private String[] field_order_type_info = new String[]{'ProcessSalesInvoicesResult'};
        public ProcessSalesInvoicesResponse_element(){
        }
        public ProcessSalesInvoicesResponse_element(DOM.XmlNode responseNode){
            Set<DOM.XmlNode> nodesParsed = new Set<DOM.XmlNode>();
            //System.assertEquals('ProcessSalesInvoicesResponse', responseNode.getName());
            DOM.XmlNode ProcessSalesInvoicesResultNode = responseNode.getChildElement('ProcessSalesInvoicesResult', 'http://www.theyukicompany.com/');
            if(ProcessSalesInvoicesResultNode == null){
                this.ProcessSalesInvoicesResult = null;
            } else{
                wwwTheyukicompanyCom.ProcessSalesInvoicesResponse_ProcessSalesInvoicesResult_element ProcessSalesInvoicesResultObj = new wwwTheyukicompanyCom.ProcessSalesInvoicesResponse_ProcessSalesInvoicesResult_element(ProcessSalesInvoicesResultNode);
                nodesParsed.add(ProcessSalesInvoicesResultNode);
                this.ProcessSalesInvoicesResult = ProcessSalesInvoicesResultObj;
            }
            //System.debug(this.ProcessSalesInvoicesResult);            
        }
    }
    public class ProcessSalesInvoicesResponse_ProcessSalesInvoicesResult_element {
        private String[] apex_schema_type_info = new String[]{'http://www.theyukicompany.com/','true','false'};
        private String[] field_order_type_info = new String[]{};
        public ProcessSalesInvoicesResponse_ProcessSalesInvoicesResult_element(DOM.XmlNode responseNode){
            Set<DOM.XmlNode> nodesParsed = new Set<DOM.XmlNode>();
        }
        public void populateXmlNode(Dom.XmlNode outerNode){
        }
    }
    public class SalesSoap {
        public String endpoint_x = 'http://api.yukiworks.nl/ws/Sales.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://www.theyukicompany.com/','wwwTheyukicompanyCom'};

        public wwwTheyukicompanyCom.ProcessSalesInvoicesResponse_ProcessSalesInvoicesResult_element ProcessSalesInvoices(String sessionId,String administrationId,wwwTheyukicompanyCom.ProcessSalesInvoices_xmlDoc_element xmlDoc) {
            wwwTheyukicompanyCom.ProcessSalesInvoices_element request_x = new wwwTheyukicompanyCom.ProcessSalesInvoices_element();
            wwwTheyukicompanyCom.ProcessSalesInvoicesResponse_element response_x;
            request_x.sessionId = sessionId;
            request_x.administrationId = administrationId;
            request_x.xmlDoc = xmlDoc;
            Map<String, wwwTheyukicompanyCom.ProcessSalesInvoicesResponse_element> response_map_x = new Map<String, wwwTheyukicompanyCom.ProcessSalesInvoicesResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
                this,
                request_x,
                response_map_x,
                new String[]{endpoint_x,
                'http://www.theyukicompany.com/ProcessSalesInvoices',
                'http://www.theyukicompany.com/',
                'ProcessSalesInvoices',
                'http://www.theyukicompany.com/',
                'ProcessSalesInvoicesResponse',
                'wwwTheyukicompanyCom.ProcessSalesInvoicesResponse_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.ProcessSalesInvoicesResult;
        }

        private DOM.XmlNode populateDoc(DOM.Document doc){
            String env = 'http://schemas.xmlsoap.org/soap/envelope/';
            String xsi = 'http://www.w3.org/2001/XMLSchema-instance';
            String xsd = 'http://www.w3.org/2001/XMLSchema';

            DOM.XmlNode envelope = doc.createRootElement('Envelope', env, 'env');
            envelope.setNamespace('xsd', xsd);
            envelope.setNamespace('xsi', xsi);
            DOM.XmlNode header = envelope.addChildElement('Header', env, '');
            AddHeader(header);
            //System.debug(doc.toXmlString());
            DOM.XmlNode body = envelope.addChildElement('Body', env, '');
            return body;
        }

        private void AddHeader(DOM.XmlNode header){
        }

        public wwwTheyukicompanyCom.ProcessSalesInvoicesResponse_ProcessSalesInvoicesResult_element ProcessSalesInvoices_Http(String sessionId,String administrationId,wwwTheyukicompanyCom.ProcessSalesInvoices_xmlDoc_element xmlDoc) {
            DOM.Document doc = new DOM.Document();
            DOM.XmlNode body = populateDoc(doc);
            DOM.XmlNode methodNode = body.addChildElement('ProcessSalesInvoices', 'http://www.theyukicompany.com/', '');            
            wwwTheyukicompanyCom.ProcessSalesInvoices_element request_x = new wwwTheyukicompanyCom.ProcessSalesInvoices_element(sessionId,administrationId,xmlDoc);
            request_x.populateXmlNode(methodNode);

            HttpRequest req = new HttpRequest();
            req.setEndpoint(endpoint_x);
            req.setMethod('POST');
            req.setHeader('Content-Type', 'text/xml; charset=UTF-8');
            req.setHeader('SOAPAction', 'http://www.theyukicompany.com/ProcessSalesInvoices');
            req.setBodyDocument(doc);
            //System.debug(req.getBody());
            Http http = new Http();
            HTTPResponse res = http.send(req);
            //System.debug(res.getBody());
            Dom.Document responseDoc = res.getBodyDocument();
            Dom.XmlNode rootNode = responseDoc.getRootElement();
            Dom.XmlNode bodyNode = rootNode.getChildElement('Body','http://schemas.xmlsoap.org/soap/envelope/');
            Dom.XmlNode ProcessSalesInvoicesResponseNode = bodyNode.getChildElement('ProcessSalesInvoicesResponse', 'http://www.theyukicompany.com/');

            wwwTheyukicompanyCom.ProcessSalesInvoicesResponse_element response_x = new wwwTheyukicompanyCom.ProcessSalesInvoicesResponse_element(ProcessSalesInvoicesResponseNode);
            return response_x.ProcessSalesInvoicesResult;
        }
    }
}
2
  • Hi Daniel, I am still getting Unable to find typeInfo for field xmlDoc .
    – sf_user
    Feb 27, 2017 at 2:59
  • @pmvsdt That you are still getting a typeInfo message suggests you are using the ProcessSalesInvoices rather than ProcessSalesInvoices_Http method. Try switching to the latter which makes a raw HTTP Request. Feb 27, 2017 at 8:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.