1

After modifying the WSDL file to remove all the tags, I successfully generated the Apex classes depending on the WSDL. However, now, as a beginner, I really do not know how to test if the classes are working. I know I can use execute anonymous in Eclipse to check if it is working. However, I do not know what to write in "source to execute". The major classes are as below:

public class servicesFastrComAuProduct {
    public class RetrievePds_element {
        public servicesFastrComAuProductData.PdsRequest request;
        public String apiKey;
        private String[] request_type_info = new String[]{'request','http://services.fastr.com.au/Product',null,'0','1','true'};
        private String[] apiKey_type_info = new String[]{'apiKey','http://services.fastr.com.au/Product',null,'0','1','true'};
        private String[] apex_schema_type_info = new String[]{'http://services.fastr.com.au/Product','true','false'};
        private String[] field_order_type_info = new String[]{'request','apiKey'};
    }
    public class RetrievePdsResponse_element {
        public servicesFastrComAuProductData.PdsResponse RetrievePdsResult;
        private String[] RetrievePdsResult_type_info = new String[]{'RetrievePdsResult','http://services.fastr.com.au/Product',null,'0','1','true'};
        private String[] apex_schema_type_info = new String[]{'http://services.fastr.com.au/Product','true','false'};
        private String[] field_order_type_info = new String[]{'RetrievePdsResult'};
    }
    public class RetrieveAssignedProductsResponse_element {
        public servicesFastrComAuProductData.RetrieveAssignedProductsResponse RetrieveAssignedProductsResult;
        private String[] RetrieveAssignedProductsResult_type_info = new String[]{'RetrieveAssignedProductsResult','http://services.fastr.com.au/Product',null,'0','1','true'};
        private String[] apex_schema_type_info = new String[]{'http://services.fastr.com.au/Product','true','false'};
        private String[] field_order_type_info = new String[]{'RetrieveAssignedProductsResult'};
    }
    public class RetrieveAssignedProducts_element {
        public String apiKey;
        private String[] apiKey_type_info = new String[]{'apiKey','http://services.fastr.com.au/Product',null,'0','1','true'};
        private String[] apex_schema_type_info = new String[]{'http://services.fastr.com.au/Product','true','false'};
        private String[] field_order_type_info = new String[]{'apiKey'};
    }
    public class ProductService_Endpoint_basicHttpBinding {
        public String endpoint_x = 'https://staging.avea.com.au:2001/ProductService.svc';
        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://services.fastr.com.au/Error', 'servicesFastrComAuError', 'http://services.fastr.com.au/Product/Data', 'servicesFastrComAuProductData', 'http://schemas.microsoft.com/2003/10/Serialization/', 'schemasMicrosoftCom200310Serializat', 'http://services.fastr.com.au/Product', 'servicesFastrComAuProduct', 'http://services.fastr.com.au/Product/Imports', 'servicesFastrComAuProductImports'};
        public servicesFastrComAuProductData.PdsResponse RetrievePds(servicesFastrComAuProductData.PdsRequest request,String apiKey) {
            servicesFastrComAuProduct.RetrievePds_element request_x = new servicesFastrComAuProduct.RetrievePds_element();
            request_x.request = request;
            request_x.apiKey = apiKey;
            servicesFastrComAuProduct.RetrievePdsResponse_element response_x;
            Map<String, servicesFastrComAuProduct.RetrievePdsResponse_element> response_map_x = new Map<String, servicesFastrComAuProduct.RetrievePdsResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              'http://services.fastr.com.au/Product/IProductService/RetrievePds',
              'http://services.fastr.com.au/Product',
              'RetrievePds',
              'http://services.fastr.com.au/Product',
              'RetrievePdsResponse',
              'servicesFastrComAuProduct.RetrievePdsResponse_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.RetrievePdsResult;
        }
        public servicesFastrComAuProductData.RetrieveAssignedProductsResponse RetrieveAssignedProducts(String apiKey) {
            servicesFastrComAuProduct.RetrieveAssignedProducts_element request_x = new servicesFastrComAuProduct.RetrieveAssignedProducts_element();
            request_x.apiKey = apiKey;
            servicesFastrComAuProduct.RetrieveAssignedProductsResponse_element response_x;
            Map<String, servicesFastrComAuProduct.RetrieveAssignedProductsResponse_element> response_map_x = new Map<String, servicesFastrComAuProduct.RetrieveAssignedProductsResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              'http://services.fastr.com.au/Product/IProductService/RetrieveAssignedProducts',
              'http://services.fastr.com.au/Product',
              'RetrieveAssignedProducts',
              'http://services.fastr.com.au/Product',
              'RetrieveAssignedProductsResponse',
              'servicesFastrComAuProduct.RetrieveAssignedProductsResponse_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.RetrieveAssignedProductsResult;
        }
    }
}

public class servicesFastrComAuProductData {
    public class ArrayOfProduct {
        public servicesFastrComAuProductData.Product[] Product;
        private String[] Product_type_info = new String[]{'Product','http://services.fastr.com.au/Product/Data',null,'0','-1','true'};
        private String[] apex_schema_type_info = new String[]{'http://services.fastr.com.au/Product/Data','true','false'};
        private String[] field_order_type_info = new String[]{'Product'};
    }
    public class Cover {
        public String Code;
        public Integer CoverTerm;
        public String Name;
        private String[] Code_type_info = new String[]{'Code','http://services.fastr.com.au/Product/Data',null,'1','1','true'};
        private String[] CoverTerm_type_info = new String[]{'CoverTerm','http://services.fastr.com.au/Product/Data',null,'0','1','true'};
        private String[] Name_type_info = new String[]{'Name','http://services.fastr.com.au/Product/Data',null,'1','1','true'};
        private String[] apex_schema_type_info = new String[]{'http://services.fastr.com.au/Product/Data','true','false'};
        private String[] field_order_type_info = new String[]{'Code','CoverTerm','Name'};
    }
    public class ArrayOfCover {
        public servicesFastrComAuProductData.Cover[] Cover;
        private String[] Cover_type_info = new String[]{'Cover','http://services.fastr.com.au/Product/Data',null,'0','-1','true'};
        private String[] apex_schema_type_info = new String[]{'http://services.fastr.com.au/Product/Data','true','false'};
        private String[] field_order_type_info = new String[]{'Cover'};
    }
    public class PdsResponse {
        public String DocumentUrl;
        private String[] DocumentUrl_type_info = new String[]{'DocumentUrl','http://services.fastr.com.au/Product/Data',null,'0','1','true'};
        private String[] apex_schema_type_info = new String[]{'http://services.fastr.com.au/Product/Data','true','false'};
        private String[] field_order_type_info = new String[]{'DocumentUrl'};
    }
    public class Product {
        public servicesFastrComAuProductData.ArrayOfCover CoverTypes;
        public String Name;
        private String[] CoverTypes_type_info = new String[]{'CoverTypes','http://services.fastr.com.au/Product/Data',null,'1','1','true'};
        private String[] Name_type_info = new String[]{'Name','http://services.fastr.com.au/Product/Data',null,'1','1','true'};
        private String[] apex_schema_type_info = new String[]{'http://services.fastr.com.au/Product/Data','true','false'};
        private String[] field_order_type_info = new String[]{'CoverTypes','Name'};
    }
    public class RetrieveAssignedProductsResponse {
        public servicesFastrComAuProductData.ArrayOfProduct Products;
        private String[] Products_type_info = new String[]{'Products','http://services.fastr.com.au/Product/Data',null,'0','1','true'};
        private String[] apex_schema_type_info = new String[]{'http://services.fastr.com.au/Product/Data','true','false'};
        private String[] field_order_type_info = new String[]{'Products'};
    }
    public class PdsRequest {
        public String CoverTypeCode;
        private String[] CoverTypeCode_type_info = new String[]{'CoverTypeCode','http://services.fastr.com.au/Product/Data',null,'1','1','true'};
        private String[] apex_schema_type_info = new String[]{'http://services.fastr.com.au/Product/Data','true','false'};
        private String[] field_order_type_info = new String[]{'CoverTypeCode'};
    }
}

public class servicesFastrComAuError {
    public class FastrError {
        public String Reason;
        private String[] Reason_type_info = new String[]{'Reason','http://services.fastr.com.au/Error',null,'0','1','true'};
        private String[] apex_schema_type_info = new String[]{'http://services.fastr.com.au/Error','true','false'};
        private String[] field_order_type_info = new String[]{'Reason'};
    }
}

There are actually five classes generated, but the other two classes are empty. I have my apikey here. I am just wondering how I input the apikey into the classes.

I wanted to put the WDSL file here, but it turns out that there are too many lines in the WDSL file. Therefore, I deleted it. Anyway, the generated classes are auto generated by Salesforce.

Thanks a lot if anyone can help me with the test for these classes.

2 Answers 2

2

The class you want to create to call the web service will be the one that has the endpoint_x member. In your case, this is ProductService_Endpoint_basicHttpBinding.

So your testing code for anonymous apex would be something like:

servicesFastrComAuProduct.ProductService_Endpoint_basicHttpBinding ws = 
    new servicesFastrComAuProduct.ProductService_Endpoint_basicHttpBinding();
string apiKey = 'shh!';
servicesFastrComAuProductData.RetrieveAssignedProductsResponse assignedProduces = 
    ws.RetrieveAssignedProducts(apiKey);

Be sure to add the endpoint https://staging.avea.com.au:2001/ProductService.svc to the Remote site settings to allow the callout to occur.

3
  • Thank you very much. This is working. I received the result with quite a lot depth. Do I do something like result.get('ArrayOfProduct').get('Product').get('CoverTypes').get('Cover').get('Name') to retrieve the data?
    – Yifei Pei
    Commented Apr 13, 2016 at 1:28
  • The returned result is like this: [Products=ArrayOfProduct: [Product= (Product: [CoverTypes=ArrayOfCover: [Cover= (Cover: [Code=TC1, Code_type_info=(Code, services.fastr.com.au/Product/Data, null, 1, 1, true), CoverTerm=36, CoverTerm_type_info=(CoverTerm, services.fastr.com.au/Product/Data, null, 0, 1, true), Name=Cover 1, Name_type_info=(Name, services.fastr.com.au/Product/Data, null, 1, 1, true), apex_schema_type_info=(services.fastr.com.au/Product/Data, true, false), field_order_type_info=(Code, CoverTerm, Name)], Cover:[Code=TC2, ......
    – Yifei Pei
    Commented Apr 13, 2016 at 1:28
  • 1
    I've found how to access the response. Thank you very much for your help.
    – Yifei Pei
    Commented Apr 13, 2016 at 6:42
0

When you create an Apex class from a WSDL, the methods in the auto-generated class call WebServiceCallout.invoke, which performs the callout to the external service. When testing these methods, you can instruct the Apex runtime to generate a fake response whenever WebServiceCallout.invoke is called. To do so, implement the WebServiceMock interface and specify a fake response for the Apex runtime to send. Here are the steps in more detail.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_callouts_wsdl2apex_testing.htm

this should provide you the framework to test your service..

2
  • First of all, I do not know what lines to write to execute the call out. The generated classes are nested so I do not know what to call and how to call them.
    – Yifei Pei
    Commented Apr 12, 2016 at 7:34
  • Second, I just want to see whether the classes are working or not. I can use Eclipse "execute anonymous" to do so. Later, I will consider unit test about it.
    – Yifei Pei
    Commented Apr 12, 2016 at 7:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .