You need to sign in to do that
Don't have an account?
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); } }
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
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.
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 ...
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: Hope it helps you!
Thanks,
Vivek
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
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