+ Start a Discussion
Jerry7Jerry7 

Methods defined as TestMethod do not support Web service callouts in Test class..

Hello Guys  I am facing the issue  last  few days let me know if anyone have good idea about this issue. I also got the 100% code coeverage of the class but the method is going fail with Methods defined as TestMethod do not support Web service callouts in Test class..Error
global with Sharing class WebserviceCreateCME {
    
    
    webservice static Void CreateCME(Id ContractId)
    {
      
        CreateCasesByContract.CreateCase();
        
    }
    
    
}
Test Class 
@isTest
Public with Sharing class TestWebserviceCreateCME {
    @IsTest Static void WebserviceTestMethod()
        
    {  
            
        Id retailRecordTypeId = [ SELECT Id,Name FROM RecordType WHERE name='Retail Contract' AND SObjectType='Contract' limit 1].Id;
        
        NAICS_Code__c nacObj = new NAICS_Code__c(
            name = 'nac code01');
        
        insert nacObj;
        
        Leasing_Agent__c l = new Leasing_Agent__c(
            name = 'Name',
            EmployeeID__c = 12,
            InActiveDate__c = date.today(),
            IS_ACTIVE__c = true,
            LeasingAgentID__c = 14
        );
        
        insert l;
        
        BP_Property__c bp_property = new BP_Property__c(
            name = 'BP_Property__c',
            AvailableArea__c = 22402,
            AvailableCount__c = 28,
            BD_Owner_Entity_ID__c = 45,
            BD_Property_ID__c = 32,
            Building_Count__c = 1,
            Colloquial_Owner__c = 'David Haug',
            InActiveDate__c = date.today(),
            IS_ACTIVE__c = true,
            Leasing_Agent__c = l.id,
            Lender__c = 'lender',            
            Market_Name__c =  'market name',
            Occupancy__c = 46,
            Owner_Entity__c = 'owner entity',
            Pay_To_Name__c = 'pay to name',
            Payment_Address__c = 'payment address',
            Payment_City__c = 'payment city',
            Payment_State__c = 'payment state',
            Payment_Suite__c = 'suite',
            Payment_Zip__c = '12323',
            PropChargeCAM__c = 47,
            PropChargeElectric__c = 1234,
            PropChargeNNN__c = 48,
            PropCurrentYearExpenses__c = 49,
            Property_Fax__c = '1231231234',
            Property_City__c = 'property city',
            Property_Code__c = 'property code',
            Property_ID__c = 49,
            Property_Manager__c = 'manager',
            Property_Name__c = 'property name',
            Property_SQFT__c = 49,
            Property_State__c = 'property state',
            Property_Street__c = 'property street',
            Property_Zip__c = '12312',
            PropGrossArea_c__c = 1234
        );
        
        insert bp_property;
        
        Building__c building = new Building__c(
            name = 'building name',
            PropertyIDYardi__c = 1227,
            PropertyIDBD__c = 23,
            PropertyCode__c = 'm2323dh',
            BuildingIDBD__c = 33,
            Building_State__c = 'building state',
            BuildingStreet__c = 'building street',
            BuildingZip__c = '12312',
            Building_City__c = 'building city',
            IS_ACTIVE__c = true,
            BDBuildingName__c = '2323 South Voss Rd',
            Google_Review_URL__c = 'http://www.google.com',
            Yelp_Review_URL__c = 'http://www.yelp.com',
            InActiveDate__c = date.today(),
            BldgGrossArea__c = 40,
            BP_Property__c = bp_property.id
        );
        
        insert building;
        
        BP_Unit__c bp_unit = new BP_Unit__c(
            name = 'bp unit name',
            BD_Availability_Status__c = 'status',
            BD_BuildingID__c = 50,
            BD_PropertyID__c = 51,
            BD_UnitID__c = 52,
            BD_UnitNum__c = '53',
            BP_Property__c = bp_property.id,
            Building__c = building.id,
            InActiveDate__c = date.today(),
            IS_ACTIVE__c = true,
            SF_Unit_Status__c = 'status',
            Size__c = 54,
            Type__c = 'type',
            Unit_Rate__c = 55,
            Unit_Recommended_Rent__c = 56,
            Unit_Sub_Category__c = 'sub category',
            Yardi_Unit_ID__c = 57,
            Yardi_Unit_Num__c = 'unit num');
        
        insert bp_unit;
        
        Account account = new Account(
            name = 'account name',
            type = 'owner',
            NAICS_Code__c = nacObj.Id,
            NAICS_Code_4__c = 'Accounting, Tax Preparation, Bookkeeping, and Payroll Services | 5412',
            Industry = 'Energy');
        
        insert account;
        
        Contact contact = new Contact(
            lastname = 'nguyen',
            accountid = account.id);
        
        insert contact;     
        
        Contact contractContact = new Contact(
            lastname = 'test',
            MailingStreet  = 'MailingStreet',
            MailingCity = 'MailingCity',
            MailingState = 'MailingState',
            MailingPostalCode = 'MailingPostalCode',
            
            accountid = account.id);
        
        insert contractContact; 
        
        Account brokeraccount = new Account(
            name = 'broker account',
            type = 'owner');
        
        insert brokeraccount;
        
        Opportunity Oppt = new Opportunity(
            Name='test opportunity', 
            Status__c = 'Actively Looking',            
            StageName='Initial Inquiry', 
            CloseDate= system.today(),
            Leasing_Agent__c = l.id,
            AccountID = account.id,
            LeadSource = 'Test Lead Source',
            Commencement_Date__c = Date.today(),
            Lease_Expiration_Date__c = Date.today(),
            Lease_Signed_Date__c = Date.today(),
            Lease_Square_Feet__c = 12345,
            Suite__c = 'Test Suite',
            Preferred_size__c = '100-500');
        
        Insert Oppt;
        
        Contract c = new Contract(
            Absorbed_Explanation__c = 'explanation',
            Additional_Monthly_Charge_Notes__c = 'notes',
            After_hour_Utilities_Detail__c = 'utility details',
            After_hour_Utilities__c = 'yes',
            ATTN__c = 'attn',
            Breakpoint__c = 6,
            Broker_Comm_Paid__c = 7,
            Brokerage_services_info_given__c = 'info given',
            Broker__c = contact.Id,
            Broker_involved__c = 'Yes',
            CAM__c = 8,
            Rent_Commencement_Date__c = date.today(),
            Comments__c = 'comments',
            Net_TI__c = 9,
            ETIC__c = 10,
            Other_Expenses__c = 11,
            Space_Leased__c = '12',
            Tenant_Prepaid__c = 13,
            TI_Applied_To__c = 'Free Rent',
            TI_Credit__c = 14,
            Other_Description__c = 'other description', 
            Contact_Email__c = 'minh@email.com',
            Base_Mo_Yr__c = date.today(),
            CPI_Cap__c = 15,
            Deposit_Transfer_Amount__c = 16,
            Elec__c = 17,
            Elec_Options__c = 'elec options',
            Escalation_Cap__c = 3,
            X1st_Mth_Rent_Received__c = 'first month rent recieved',     
            Guarantor__c = contact.id,
            Holdover_Lease_Backdated__c = 'holdover lease backdated',
            Holdover_Not_Std__c = 17,
            How_Long__c = date.today(),
            Initial_Agreement_Start_Date__c = date.today(),
            Insurance__c = 18,
            Lease_Agreement__c = 'lease agreement',
            Lease_Type__c = 'lease type',
            Lease_Type_Comments__c = 'lease comments',
            MLS_Comment__c = 'mls comment',
            MLS_Type__c = 'Lease',
            Non_Standard_Fee_Desc__c = 'non std fee desc',
            Non_Std_Fee__c = '24',
            OPEX_Base__c = date.today(),
            OPEX_Stop__c = 25,
            Other_Monthly_Charge__c = 26,
            Other_Monthly_Charge_Desc__c = 'monthly charge desc',
            Other_Provisions__c = 'other provisions',
            Parking__c = 27,
            PT_Other_Desc__c = 'pt other desc',
            PT_Type__c = 'type',
            Payment_not_in_full_details__c = 'payment not in full details',
            Payment_Type__c = 'payment type',
            Percent_Rent__c = 28,
            Prior_Annual_Rate__c = 29,
            Pro_Rata_Share__c = 30,
            Promo_Mktg__c = 31,
            Renewal_Option_Detail__c = 'renewal option detail',
            Renewal_Option__c = 'renewal option',
            Rent_Adjustment__c = 'rent adjustment',
            Reserved_Parking_Detail__c = 'reserved parking detail',
            Reserved_Parking__c = 'reserved parking', 
            Right_of_First_Refusal_Detail__c = 'refusal detail',
            Right_of_First_Refusal__c = 'first refusal', 
            Security_Deposit__c = 32,
            Security_Deposit_Received__c = '33',
            Signage__c = 34,
            Special_Provisions__c = 'special provisions',
            Storage__c = 76,
            Taxes__c = 35,
            Tenant_From__c = 'tenant from',
            Term_Type__c = 'term type',
            Termination_Option_Date__c = date.today(),
            Termination_Option_Detail__c = 'termination option detail',
            Termination_Option__c = 'termination option',         
            Unit_Num_On_Lease__c = 'a02',
            USA_Patriot_Act__c = 'usa patriot act',        
            Prorated_rent_due__c = 37,
            What_Happened__c = 'what happened',
            Late_Fee_Pct__c = 38,
            Rent_Due_Date__c = 'rent due date',
            Hold_Over_Percentage__c = 39,
            //MLS_TRAN_ID__c,
            deactivation_reason__c = 'deactivation reason',
            deactivation_date__c = date.today(),
            CME_Case_ID__c = 40,
            accountid = account.id,
            Building__c = building.id,
            BP_Unit__c = bp_unit.id,
            Manual_Contract_End_Date__c = system.today(),
            Status = 'Lease Signed By Tenant',
            Contract_Contact__c = contractContact.Id,
            CustomerSignedDate = system.today(),            
            Opportunity__c = oppt.id,
            RecordTypeID = retailRecordTypeId
        );
        
        
        insert c;
        
        
        WebserviceCreateCME.CreateCME(c.Id);
    }
}




Best Answer chosen by Jerry7
VivekShindeVivekShinde
Hi Jerry,

Is the method which performs callout also getting called from a trigger, Contract object's trigger or some other? If so, you need to specify the Test.setMock method above the statement performing dml operation on that object in the test class.

Thanks,
Vivek Shinde

All Answers

Tarun Khatri (TK)Tarun Khatri (TK)
Hello Jerry,

Salesforce won't support callout from Test class. You can implement Mock callout for the test class as describe in below link or update main class to handle test class return using Test.isRunnigTest() method:

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

-Thanks,
TK

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
Jerry7Jerry7
Hello Trun ,Thanks For Reply..

I had created the Mock Class and follow same as you suggested but still it throw the same error  here i am putting code please correct me if ...

 
Mock Class

global class WebserviceCreateCMEMock implements WebServiceMock {
    global void doInvoke(
        Object stub,
        Object request,
        Map<String, Object> response,
        String endpoint,
        String soapAction,
        String requestName,
        String responseNS,
        String responseName,
        String responseType) 
    {
        soapSforceComSchemasClassWebservice.WebserviceCreateCME response_x = new soapSforceComSchemasClassWebservice.WebserviceCreateCME();
        response_x.endpoint_x  = 'https://cs43.salesforce.com/services/Soap/class/WebserviceCreateCME';
        response.put('endpoint' , response_x ); 
        
    }
      
    
}
@isTest
Public with Sharing class TestWebserviceCreateCME {
    @IsTest Static void WebserviceTestMethod()
        
    {  
            
        Id retailRecordTypeId = [ SELECT Id,Name FROM RecordType WHERE name='Retail Contract' AND SObjectType='Contract' limit 1].Id;
        
        NAICS_Code__c nacObj = new NAICS_Code__c(
            name = 'nac code01');
        
        insert nacObj;
        
        Leasing_Agent__c l = new Leasing_Agent__c(
            name = 'Name',
            EmployeeID__c = 12,
            InActiveDate__c = date.today(),
            IS_ACTIVE__c = true,
            LeasingAgentID__c = 14
        );
        
        insert l;
        
        BP_Property__c bp_property = new BP_Property__c(
            name = 'BP_Property__c',
            AvailableArea__c = 22402,
            AvailableCount__c = 28,
            BD_Owner_Entity_ID__c = 45,
            BD_Property_ID__c = 32,
            Building_Count__c = 1,
            Colloquial_Owner__c = 'David Haug',
            InActiveDate__c = date.today(),
            IS_ACTIVE__c = true,
            Leasing_Agent__c = l.id,
            Lender__c = 'lender',            
            Market_Name__c =  'market name',
            Occupancy__c = 46,
            Owner_Entity__c = 'owner entity',
            Pay_To_Name__c = 'pay to name',
            Payment_Address__c = 'payment address',
            Payment_City__c = 'payment city',
            Payment_State__c = 'payment state',
            Payment_Suite__c = 'suite',
            Payment_Zip__c = '12323',
            PropChargeCAM__c = 47,
            PropChargeElectric__c = 1234,
            PropChargeNNN__c = 48,
            PropCurrentYearExpenses__c = 49,
            Property_Fax__c = '1231231234',
            Property_City__c = 'property city',
            Property_Code__c = 'property code',
            Property_ID__c = 49,
            Property_Manager__c = 'manager',
            Property_Name__c = 'property name',
            Property_SQFT__c = 49,
            Property_State__c = 'property state',
            Property_Street__c = 'property street',
            Property_Zip__c = '12312',
            PropGrossArea_c__c = 1234
        );
        
        insert bp_property;
        
        Building__c building = new Building__c(
            name = 'building name',
            PropertyIDYardi__c = 1227,
            PropertyIDBD__c = 23,
            PropertyCode__c = 'm2323dh',
            BuildingIDBD__c = 33,
            Building_State__c = 'building state',
            BuildingStreet__c = 'building street',
            BuildingZip__c = '12312',
            Building_City__c = 'building city',
            IS_ACTIVE__c = true,
            BDBuildingName__c = '2323 South Voss Rd',
            Google_Review_URL__c = 'http://www.google.com',
            Yelp_Review_URL__c = 'http://www.yelp.com',
            InActiveDate__c = date.today(),
            BldgGrossArea__c = 40,
            BP_Property__c = bp_property.id
        );
        
        insert building;
        
        BP_Unit__c bp_unit = new BP_Unit__c(
            name = 'bp unit name',
            BD_Availability_Status__c = 'status',
            BD_BuildingID__c = 50,
            BD_PropertyID__c = 51,
            BD_UnitID__c = 52,
            BD_UnitNum__c = '53',
            BP_Property__c = bp_property.id,
            Building__c = building.id,
            InActiveDate__c = date.today(),
            IS_ACTIVE__c = true,
            SF_Unit_Status__c = 'status',
            Size__c = 54,
            Type__c = 'type',
            Unit_Rate__c = 55,
            Unit_Recommended_Rent__c = 56,
            Unit_Sub_Category__c = 'sub category',
            Yardi_Unit_ID__c = 57,
            Yardi_Unit_Num__c = 'unit num');
        
        insert bp_unit;
        
        Account account = new Account(
            name = 'account name',
            type = 'owner',
            NAICS_Code__c = nacObj.Id,
            NAICS_Code_4__c = 'Accounting, Tax Preparation, Bookkeeping, and Payroll Services | 5412',
            Industry = 'Energy');
        
        insert account;
        
        Contact contact = new Contact(
            lastname = 'nguyen',
            accountid = account.id);
        
        insert contact;     
        
        Contact contractContact = new Contact(
            lastname = 'test',
            MailingStreet  = 'MailingStreet',
            MailingCity = 'MailingCity',
            MailingState = 'MailingState',
            MailingPostalCode = 'MailingPostalCode',
            
            accountid = account.id);
        
        insert contractContact; 
        
        Account brokeraccount = new Account(
            name = 'broker account',
            type = 'owner');
        
        insert brokeraccount;
        
        Opportunity Oppt = new Opportunity(
            Name='test opportunity', 
            Status__c = 'Actively Looking',            
            StageName='Initial Inquiry', 
            CloseDate= system.today(),
            Leasing_Agent__c = l.id,
            AccountID = account.id,
            LeadSource = 'Test Lead Source',
            Commencement_Date__c = Date.today(),
            Lease_Expiration_Date__c = Date.today(),
            Lease_Signed_Date__c = Date.today(),
            Lease_Square_Feet__c = 12345,
            Suite__c = 'Test Suite',
            Preferred_size__c = '100-500');
        
        Insert Oppt;
        
        Contract c = new Contract(
            Absorbed_Explanation__c = 'explanation',
            Additional_Monthly_Charge_Notes__c = 'notes',
            After_hour_Utilities_Detail__c = 'utility details',
            After_hour_Utilities__c = 'yes',
            ATTN__c = 'attn',
            Breakpoint__c = 6,
            Broker_Comm_Paid__c = 7,
            Brokerage_services_info_given__c = 'info given',
            Broker__c = contact.Id,
            Broker_involved__c = 'Yes',
            CAM__c = 8,
            Rent_Commencement_Date__c = date.today(),
            Comments__c = 'comments',
            Net_TI__c = 9,
            ETIC__c = 10,
            Other_Expenses__c = 11,
            Space_Leased__c = '12',
            Tenant_Prepaid__c = 13,
            TI_Applied_To__c = 'Free Rent',
            TI_Credit__c = 14,
            Other_Description__c = 'other description', 
            Contact_Email__c = 'minh@email.com',
            Base_Mo_Yr__c = date.today(),
            CPI_Cap__c = 15,
            Deposit_Transfer_Amount__c = 16,
            Elec__c = 17,
            Elec_Options__c = 'elec options',
            Escalation_Cap__c = 3,
            X1st_Mth_Rent_Received__c = 'first month rent recieved',     
            Guarantor__c = contact.id,
            Holdover_Lease_Backdated__c = 'holdover lease backdated',
            Holdover_Not_Std__c = 17,
            How_Long__c = date.today(),
            Initial_Agreement_Start_Date__c = date.today(),
            Insurance__c = 18,
            Lease_Agreement__c = 'lease agreement',
            Lease_Type__c = 'lease type',
            Lease_Type_Comments__c = 'lease comments',
            MLS_Comment__c = 'mls comment',
            MLS_Type__c = 'Lease',
            Non_Standard_Fee_Desc__c = 'non std fee desc',
            Non_Std_Fee__c = '24',
            OPEX_Base__c = date.today(),
            OPEX_Stop__c = 25,
            Other_Monthly_Charge__c = 26,
            Other_Monthly_Charge_Desc__c = 'monthly charge desc',
            Other_Provisions__c = 'other provisions',
            Parking__c = 27,
            PT_Other_Desc__c = 'pt other desc',
            PT_Type__c = 'type',
            Payment_not_in_full_details__c = 'payment not in full details',
            Payment_Type__c = 'payment type',
            Percent_Rent__c = 28,
            Prior_Annual_Rate__c = 29,
            Pro_Rata_Share__c = 30,
            Promo_Mktg__c = 31,
            Renewal_Option_Detail__c = 'renewal option detail',
            Renewal_Option__c = 'renewal option',
            Rent_Adjustment__c = 'rent adjustment',
            Reserved_Parking_Detail__c = 'reserved parking detail',
            Reserved_Parking__c = 'reserved parking', 
            Right_of_First_Refusal_Detail__c = 'refusal detail',
            Right_of_First_Refusal__c = 'first refusal', 
            Security_Deposit__c = 32,
            Security_Deposit_Received__c = '33',
            Signage__c = 34,
            Special_Provisions__c = 'special provisions',
            Storage__c = 76,
            Taxes__c = 35,
            Tenant_From__c = 'tenant from',
            Term_Type__c = 'term type',
            Termination_Option_Date__c = date.today(),
            Termination_Option_Detail__c = 'termination option detail',
            Termination_Option__c = 'termination option',         
            Unit_Num_On_Lease__c = 'a02',
            USA_Patriot_Act__c = 'usa patriot act',        
            Prorated_rent_due__c = 37,
            What_Happened__c = 'what happened',
            Late_Fee_Pct__c = 38,
            Rent_Due_Date__c = 'rent due date',
            Hold_Over_Percentage__c = 39,
            //MLS_TRAN_ID__c,
            deactivation_reason__c = 'deactivation reason',
            deactivation_date__c = date.today(),
            CME_Case_ID__c = 40,
            accountid = account.id,
            Building__c = building.id,
            BP_Unit__c = bp_unit.id,
            Manual_Contract_End_Date__c = system.today(),
            Status = 'Lease Signed By Tenant',
            Contract_Contact__c = contractContact.Id,
            CustomerSignedDate = system.today(),            
            Opportunity__c = oppt.id,
            RecordTypeID = retailRecordTypeId
        );
        
        
        insert c;
        
        Test.setMock(WebServiceMock.class, new WebserviceCreateCMEMock());
        WebserviceCreateCME.CreateCME(c.Id);
    }
}

//Generated by wsdl2apex

public class AsyncSoapSforceComSchemasClassWebservice {
    public class CreateCMEResponse_elementFuture extends System.WebServiceCalloutFuture {
        public String getValue() {
            soapSforceComSchemasClassWebservice.CreateCMEResponse_element response = (soapSforceComSchemasClassWebservice.CreateCMEResponse_element)System.WebServiceCallout.endInvoke(this);
            return response.result;
        }
    }
    public class AsyncWebserviceCreateCME {
        public String endpoint_x = 'https://cs43.salesforce.com/services/Soap/class/WebserviceCreateCME';
        public Map<String,String> inputHttpHeaders_x;
        public String clientCertName_x;
        public Integer timeout_x;
        public soapSforceComSchemasClassWebservice.SessionHeader_element SessionHeader;
        public soapSforceComSchemasClassWebservice.CallOptions_element CallOptions;
        public soapSforceComSchemasClassWebservice.DebuggingHeader_element DebuggingHeader;
        public soapSforceComSchemasClassWebservice.AllowFieldTruncationHeader_element AllowFieldTruncationHeader;
        public soapSforceComSchemasClassWebservice.DebuggingInfo_element DebuggingInfo;
        private String SessionHeader_hns = 'SessionHeader=http://soap.sforce.com/schemas/class/WebserviceCreateCME';
        private String CallOptions_hns = 'CallOptions=http://soap.sforce.com/schemas/class/WebserviceCreateCME';
        private String DebuggingHeader_hns = 'DebuggingHeader=http://soap.sforce.com/schemas/class/WebserviceCreateCME';
        private String AllowFieldTruncationHeader_hns = 'AllowFieldTruncationHeader=http://soap.sforce.com/schemas/class/WebserviceCreateCME';
        private String DebuggingInfo_hns = 'DebuggingInfo=http://soap.sforce.com/schemas/class/WebserviceCreateCME';
        private String[] ns_map_type_info = new String[]{'http://soap.sforce.com/schemas/class/WebserviceCreateCME', 'soapSforceComSchemasClassWebservice'};
        public AsyncSoapSforceComSchemasClassWebservice.CreateCMEResponse_elementFuture beginCreateCME(System.Continuation continuation,String message) {
            soapSforceComSchemasClassWebservice.CreateCME_element request_x = new soapSforceComSchemasClassWebservice.CreateCME_element();
            request_x.message = message;
            return (AsyncSoapSforceComSchemasClassWebservice.CreateCMEResponse_elementFuture) System.WebServiceCallout.beginInvoke(
              this,
              request_x,
              AsyncSoapSforceComSchemasClassWebservice.CreateCMEResponse_elementFuture.class,
              continuation,
              new String[]{endpoint_x,
              '',
              'http://soap.sforce.com/schemas/class/WebserviceCreateCME',
              'CreateCME',
              'http://soap.sforce.com/schemas/class/WebserviceCreateCME',
              'CreateCMEResponse',
              'soapSforceComSchemasClassWebservice.CreateCMEResponse_element'}
            );
        }
    }
}
//Generated by wsdl2apex

public class soapSforceComSchemasClassWebservice {
    public class LogInfo {
        public String category;
        public String level;
        private String[] category_type_info = new String[]{'category','http://soap.sforce.com/schemas/class/WebserviceCreateCME',null,'1','1','false'};
        private String[] level_type_info = new String[]{'level','http://soap.sforce.com/schemas/class/WebserviceCreateCME',null,'1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://soap.sforce.com/schemas/class/WebserviceCreateCME','true','false'};
        private String[] field_order_type_info = new String[]{'category','level'};
    }
    public class DebuggingInfo_element {
        public String debugLog;
        private String[] debugLog_type_info = new String[]{'debugLog','http://soap.sforce.com/schemas/class/WebserviceCreateCME',null,'1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://soap.sforce.com/schemas/class/WebserviceCreateCME','true','false'};
        private String[] field_order_type_info = new String[]{'debugLog'};
    }
    public class address {
        public String city;
        public String country;
        public String countryCode;
        public String geocodeAccuracy;
        public String postalCode;
        public String state;
        public String stateCode;
        public String street;
        private String[] city_type_info = new String[]{'city','http://soap.sforce.com/schemas/class/WebserviceCreateCME',null,'1','1','false'};
        private String[] country_type_info = new String[]{'country','http://soap.sforce.com/schemas/class/WebserviceCreateCME',null,'1','1','false'};
        private String[] countryCode_type_info = new String[]{'countryCode','http://soap.sforce.com/schemas/class/WebserviceCreateCME',null,'1','1','false'};
        private String[] geocodeAccuracy_type_info = new String[]{'geocodeAccuracy','http://soap.sforce.com/schemas/class/WebserviceCreateCME',null,'1','1','false'};
        private String[] postalCode_type_info = new String[]{'postalCode','http://soap.sforce.com/schemas/class/WebserviceCreateCME',null,'1','1','false'};
        private String[] state_type_info = new String[]{'state','http://soap.sforce.com/schemas/class/WebserviceCreateCME',null,'1','1','false'};
        private String[] stateCode_type_info = new String[]{'stateCode','http://soap.sforce.com/schemas/class/WebserviceCreateCME',null,'1','1','false'};
        private String[] street_type_info = new String[]{'street','http://soap.sforce.com/schemas/class/WebserviceCreateCME',null,'1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://soap.sforce.com/schemas/class/WebserviceCreateCME','true','false'};
        private String[] field_order_type_info = new String[]{'city','country','countryCode','geocodeAccuracy','postalCode','state','stateCode','street'};
    }
    public class CreateCME_element {
        public String message;
        private String[] message_type_info = new String[]{'message','http://soap.sforce.com/schemas/class/WebserviceCreateCME',null,'1','1','true'};
        private String[] apex_schema_type_info = new String[]{'http://soap.sforce.com/schemas/class/WebserviceCreateCME','true','false'};
        private String[] field_order_type_info = new String[]{'message'};
    }
    public class SessionHeader_element {
        public String sessionId;
        private String[] sessionId_type_info = new String[]{'sessionId','http://soap.sforce.com/schemas/class/WebserviceCreateCME',null,'1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://soap.sforce.com/schemas/class/WebserviceCreateCME','true','false'};
        private String[] field_order_type_info = new String[]{'sessionId'};
    }
    public class CallOptions_element {
        public String client;
        private String[] client_type_info = new String[]{'client','http://soap.sforce.com/schemas/class/WebserviceCreateCME',null,'1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://soap.sforce.com/schemas/class/WebserviceCreateCME','true','false'};
        private String[] field_order_type_info = new String[]{'client'};
    }
    public class DebuggingHeader_element {
        public soapSforceComSchemasClassWebservice.LogInfo[] categories;
        public String debugLevel;
        private String[] categories_type_info = new String[]{'categories','http://soap.sforce.com/schemas/class/WebserviceCreateCME',null,'0','-1','false'};
        private String[] debugLevel_type_info = new String[]{'debugLevel','http://soap.sforce.com/schemas/class/WebserviceCreateCME',null,'1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://soap.sforce.com/schemas/class/WebserviceCreateCME','true','false'};
        private String[] field_order_type_info = new String[]{'categories','debugLevel'};
    }
    public class location {
        public Double latitude;
        public Double longitude;
        private String[] latitude_type_info = new String[]{'latitude','http://soap.sforce.com/schemas/class/WebserviceCreateCME',null,'1','1','false'};
        private String[] longitude_type_info = new String[]{'longitude','http://soap.sforce.com/schemas/class/WebserviceCreateCME',null,'1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://soap.sforce.com/schemas/class/WebserviceCreateCME','true','false'};
        private String[] field_order_type_info = new String[]{'latitude','longitude'};
    }
    public class CreateCMEResponse_element {
        public String result;
        private String[] result_type_info = new String[]{'result','http://soap.sforce.com/schemas/class/WebserviceCreateCME',null,'1','1','true'};
        private String[] apex_schema_type_info = new String[]{'http://soap.sforce.com/schemas/class/WebserviceCreateCME','true','false'};
        private String[] field_order_type_info = new String[]{'result'};
    }
    public class AllowFieldTruncationHeader_element {
        public Boolean allowFieldTruncation;
        private String[] allowFieldTruncation_type_info = new String[]{'allowFieldTruncation','http://soap.sforce.com/schemas/class/WebserviceCreateCME',null,'1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://soap.sforce.com/schemas/class/WebserviceCreateCME','true','false'};
        private String[] field_order_type_info = new String[]{'allowFieldTruncation'};
    }
    public class WebserviceCreateCME {
        public String endpoint_x = 'https://cs43.salesforce.com/services/Soap/class/WebserviceCreateCME';
        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 soapSforceComSchemasClassWebservice.SessionHeader_element SessionHeader;
        public soapSforceComSchemasClassWebservice.CallOptions_element CallOptions;
        public soapSforceComSchemasClassWebservice.DebuggingHeader_element DebuggingHeader;
        public soapSforceComSchemasClassWebservice.AllowFieldTruncationHeader_element AllowFieldTruncationHeader;
        public soapSforceComSchemasClassWebservice.DebuggingInfo_element DebuggingInfo;
        private String SessionHeader_hns = 'SessionHeader=http://soap.sforce.com/schemas/class/WebserviceCreateCME';
        private String CallOptions_hns = 'CallOptions=http://soap.sforce.com/schemas/class/WebserviceCreateCME';
        private String DebuggingHeader_hns = 'DebuggingHeader=http://soap.sforce.com/schemas/class/WebserviceCreateCME';
        private String AllowFieldTruncationHeader_hns = 'AllowFieldTruncationHeader=http://soap.sforce.com/schemas/class/WebserviceCreateCME';
        private String DebuggingInfo_hns = 'DebuggingInfo=http://soap.sforce.com/schemas/class/WebserviceCreateCME';
        private String[] ns_map_type_info = new String[]{'http://soap.sforce.com/schemas/class/WebserviceCreateCME', 'soapSforceComSchemasClassWebservice'};
        public String CreateCME(String message) {
            soapSforceComSchemasClassWebservice.CreateCME_element request_x = new soapSforceComSchemasClassWebservice.CreateCME_element();
            request_x.message = message;
            soapSforceComSchemasClassWebservice.CreateCMEResponse_element response_x;
            Map<String, soapSforceComSchemasClassWebservice.CreateCMEResponse_element> response_map_x = new Map<String, soapSforceComSchemasClassWebservice.CreateCMEResponse_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              '',
              'http://soap.sforce.com/schemas/class/WebserviceCreateCME',
              'CreateCME',
              'http://soap.sforce.com/schemas/class/WebserviceCreateCME',
              'CreateCMEResponse',
              'soapSforceComSchemasClassWebservice.CreateCMEResponse_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.result;
        }
    }
}


 
VivekShindeVivekShinde
Hi Jerry,

In the doInvoke method of the mock class, you need to create an instance of the CreateCMEResponse_element class. Also, in the response map you need to put key as 'response_x' and not 'endpoint'. Apparentely, you need to write following lines inside the doInvoke method:
soapSforceComSchemasClassWebservice.CreateCMEResponse_element responseElementObj = new soapSforceComSchemasClassWebservice.CreateCMEResponse_element();
responseElementObj.result = 'Your expected result';
response.put('response_x', responseElementObj);
Hope it helps you!

Thanks,
Vivek
Jerry7Jerry7

Hello Vivek ,thanks for reply..!
I had tried your code but still getting same error ..

Methods defined as TestMethod do not support Web service callouts

VivekShindeVivekShinde
Hi Jerry,

Is the method which performs callout also getting called from a trigger, Contract object's trigger or some other? If so, you need to specify the Test.setMock method above the statement performing dml operation on that object in the test class.

Thanks,
Vivek Shinde
This was selected as the best answer