[SalesForce] Test Class for WSDL2Apex class generated by Salesforce Partner WSDL

I'm using Partner WSDL in my org and generated an APEX class (WSDL2Apex) to connect my org with another salesforce environment.

Have anyone done such earlier and if written the test class for its code coverage and help me with that here.

//Generated by wsdl2apex

public class vPartnerSoapSforceCom {
    public class InvalidateSessionsResult {
        public vPartnerSoapSforceCom.Error[] errors;
        public Boolean success;
        private String[] errors_type_info = new String[]{'errors','urn:partner.soap.sforce.com',null,'0','-1','false'};
        private String[] success_type_info = new String[]{'success','urn:partner.soap.sforce.com',null,'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[]{'errors','success'};
    }
    public class describePrimaryCompactLayoutsResponse_element {
        public vPartnerSoapSforceCom.DescribeCompactLayout[] result;
        private String[] result_type_info = new String[]{'result','urn:partner.soap.sforce.com',null,'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[]{'result'};
    }
    public class DescribeAppMenuResult {
        public vPartnerSoapSforceCom.DescribeAppMenuItem[] appMenuItems;
        private String[] appMenuItems_type_info = new String[]{'appMenuItems','urn:partner.soap.sforce.com',null,'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[]{'appMenuItems'};
    }
    public class DescribeColor {
        public String color;
        public String context;
  • This is just a few lines of around 4000 lines of APEX code generated.

As the Partner WSDL is not tightly bound to the organisation and will remain same for anyone for a particular release. Here I'm looking for someone who has done the same and can share his test class as that will definitely work for me.

..

Additionally I'm aware of mockups and if no one has already worked on such test class earlier I'll write my own and share the code with the community so someone will get benefited in future.

Best Answer

Use mock callouts by either implementing an interface or using static resources. Mock callouts allow you to specify the response to return in the test instead of actually calling the web service.The Test.setMock method informs the runtime that mock callouts are used in the test method. For examples please refer trailhead badge Apex Integration Services:Apex REST Callouts. Here is the link : https://trailhead.salesforce.com/apex_integration_services/apex_integration_rest_callouts

Related Topic