[SalesForce] Get data from SAP to Salesforce using WSDL

I have attached the WSDL2Apex class for getting data Sap to Salesforce. I am bit confused about this Apex code is correct or not for this WSDL file which is to connect the WSDL to get data from SAP.//Generated by wsdl2apex

public class sapComDocumentSapSoapFunctionsMcS {
    public class zsd_cust_det_webservice {
        public String endpoint_x = 'http://serverapp5.css.local:80/sap/bc/srt/rfc/sap/zsd_cust_det_webservice/100/zsd_cust_det_webservice/zsd_cust_det_webservice';
        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[]{'urn:sap-com:document:sap:soap:functions:mc-style', 'sapComDocumentSapSoapFunctionsMcS', 'urn:sap-com:document:sap:rfc:functions', 'sapComDocumentSapRfcFunctions'};
        public sapComDocumentSapSoapFunctionsMcS.ZsdTCustDet ZsdCustWebservDemo(String IvAcctNo) {
            sapComDocumentSapSoapFunctionsMcS.ZsdCustWebservDemo_element request_x = new sapComDocumentSapSoapFunctionsMcS.ZsdCustWebservDemo_element();
            sapComDocumentSapSoapFunctionsMcS.ZsdCustWebservDemoResponse_element response_x;
            request_x.IvAcctNo = IvAcctNo;
            Map<String, sapComDocumentSapSoapFunctionsMcS.ZsdCustWebservDemoResponse_element> response_map_x = new Map<String, sapComDocumentSapSoapFunctionsMcS.ZsdCustWebservDemoResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              '',
              'urn:sap-com:document:sap:soap:functions:mc-style',
              'ZsdCustWebservDemo',
              'urn:sap-com:document:sap:soap:functions:mc-style',
              'ZsdCustWebservDemoResponse',
              'sapComDocumentSapSoapFunctionsMcS.ZsdCustWebservDemoResponse_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.EtAccDet;
        }
    }
    public class ZsdCustWebservDemo_element {
        public String IvAcctNo;
        private String[] IvAcctNo_type_info = new String[]{'IvAcctNo','urn:sap-com:document:sap:rfc:functions','char10','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'urn:sap-com:document:sap:soap:functions:mc-style','false','true'};
        private String[] field_order_type_info = new String[]{'IvAcctNo'};
    }
    public class ZsdSCustDet {
        public String AcctNo;
        public String SalesOrdNo;
        public String PoNo;
        public String PoDate;
        public String NetVal;
        public String Currency_x;
        private String[] AcctNo_type_info = new String[]{'AcctNo','urn:sap-com:document:sap:rfc:functions','char10','1','1','false'};
        private String[] SalesOrdNo_type_info = new String[]{'SalesOrdNo','urn:sap-com:document:sap:rfc:functions','char10','1','1','false'};
        private String[] PoNo_type_info = new String[]{'PoNo','urn:sap-com:document:sap:rfc:functions','char20','1','1','false'};
        private String[] PoDate_type_info = new String[]{'PoDate','urn:sap-com:document:sap:rfc:functions','date','1','1','false'};
        private String[] NetVal_type_info = new String[]{'NetVal','urn:sap-com:document:sap:rfc:functions','curr15.2','1','1','false'};
        private String[] Currency_x_type_info = new String[]{'Currency','urn:sap-com:document:sap:rfc:functions','cuky5','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'urn:sap-com:document:sap:soap:functions:mc-style','false','true'};
        private String[] field_order_type_info = new String[]{'AcctNo','SalesOrdNo','PoNo','PoDate','NetVal','Currency_x'};
    }
    public class ZsdTCustDet {
        public sapComDocumentSapSoapFunctionsMcS.ZsdSCustDet[] item;
        private String[] item_type_info = new String[]{'item','urn:sap-com:document:sap:soap:functions:mc-style','ZsdSCustDet','0','-1','false'};
        private String[] apex_schema_type_info = new String[]{'urn:sap-com:document:sap:soap:functions:mc-style','false','true'};
        private String[] field_order_type_info = new String[]{'item'};
    }
    public class ZsdCustWebservDemoResponse_element {
        public sapComDocumentSapSoapFunctionsMcS.ZsdTCustDet EtAccDet;
        private String[] EtAccDet_type_info = new String[]{'EtAccDet','urn:sap-com:document:sap:soap:functions:mc-style','ZsdTCustDet','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'urn:sap-com:document:sap:soap:functions:mc-style','false','true'};
        private String[] field_order_type_info = new String[]{'EtAccDet'};
    }
}

Apex code:
public class test
{

    public test(ApexPages.StandardController controller) {

    }


    public test(set<SAP__c> i)
{

list<SAP__c>lic=[select Name from SAP__c where id in: i];
for( SAP__c s:lic)
{

sapComDocumentSapSoapFunctionsMcS.zsd_cust_det_webservice create=new sapComDocumentSapSoapFunctionsMcS.zsd_cust_det_webservice();
 create.ZsdCustWebservDemo(s.Name);

}
}
}

Best Answer

There is an excellent topic 'Understanding the Generated Code' in the Apex Developers guide here, which describes what your getting from the Apex2WSDL tool and an example of how to use it. Of course each Web Service is different, so I cannot comment on specifically. So here are some general observations.

  • Authentication? I can see that its a basic account enquiry service. It does not appear to have any authentication needs (typically these are expressed in the WSDL via soap:header's), i assume thats ok for your demo purposes.
  • Bulkification? If you are in control of the web service you may want to ask the author to accept a list of customer names, which will avoid you looping over them. Note that Apex has a limit of 10 maximum call outs of this kind per request. Limiting the number of records from your SAP__c table that can be processed.

Finally you should also review the support for Mocking Web Service callouts when it comes time to write some Apex tests to cover this code you will need it.

Related Topic