You need to sign in to do that
Don't have an account?
Test Class Issue (Error : System.LimitException: Too many SOQL queries: 101)
Hi,
I do have a Test Class, which is failing. Can anyone help regarding the same. The error as below
Error : System.LimitException: Too many SOQL queries: 101
@isTest public class RevenueWaterFallExt_Test { static testmethod void method1(){ Account a = new Account(); a.Name = 'ABC Test'; a.BillingStreet = '1709 Long Prairie Rd'; a.BillingCity = 'Allen'; a.BillingState = 'TX'; a.BillingCountry = 'USA'; a.Website = 'http://www.yahoo.com'; a.Industry = 'Cable'; a.Vertical__c = 'Cable'; insert a; List<Opportunity> oList = new List<Opportunity> { new Opportunity(Name ='00New mAWS Deal', AccountID =a.id, StageName = '7 - Won', Amount = 3000, Reason__c = 'Hehehe', CloseDate = System.today(), What_did_we_learn__c = 'What_did_we_learnnnnnnnn', Contract_Term__c = 5, CYR__c = 11111, TOB__c='Renewal'), new Opportunity( Name = '01mAWS Usage', AccountId = a.id, StageName = '7 - Won', CloseDate = System.today(), TOB__c='Renewal', Reason__c = 'Hahaha', Contract_Term__c = 5, CYR__c = 11111, What_did_we_learn__c = 'What_did_we_learnnnnnnnn', Amount = 555888555) }; insert oList; Account_Plan__c ap = new Account_Plan__c(Name ='ABC Account Plan', Account__c = a.Id); insert ap; Revenue_Waterfall__c r = new Revenue_Waterfall__c(); r.account_plan__c = ap.Id; insert r; Test.setCurrentPageReference(new PageReference('Page.RevenueWaterfallInput')); System.currentPageReference().getParameters().put('apId', ap.Id); System.currentPageReference().getParameters().put('aId', a.Id); ApexPages.StandardController c = new ApexPages.StandardController(r); RevenueWaterFallExt h = new RevenueWaterFallExt(c); h.customSave(); h.customCancel(); h.revWater = new List<Revenue_Waterfall__c>(); h.revWater.add(new Revenue_Waterfall__c()); h.customSave(); } static testmethod void soldBusinessMethod(){ //insert Account Account a = new Account(); a.Name = 'Test'; a.BillingStreet = '1709 Long Prairie Rd'; a.BillingCity = 'Allen'; a.BillingState = 'TX'; a.BillingCountry = 'USA'; a.Website = 'http://www.yahoo.com'; a.Industry = 'Cable'; a.Vertical__c = 'Cable'; insert a; // insert Vertical zVertical__c v = new zVertical__c(); v.Name ='EMEA'; insert v; //insert product Product2 prod = new Product2(Name = 'Laptop X200', Family = 'Hardware'); insert prod; //insert PriceboolEntry Id pricebookId = Test.getStandardPricebookId(); PricebookEntry standardPrice = new PricebookEntry(Pricebook2Id = pricebookId, Product2Id = prod.Id, UnitPrice = 10000, IsActive = true); insert standardPrice; Opportunity opp = new Opportunity(); opp.Name = 'Test'; opp.StageName = '1 - Prospect'; opp.CloseDate = System.Today(); opp.Projected_Revenue_Start_Date__c = System.today(); opp.Training_Start_Date__c = System.today(); opp.contract_term__c = 1; opp.tob__c = 'New'; opp.vertical__c = v.Id; opp.AccountId = a.Id; opp.Product_1__c = prod.id; opp.AACV__c = 1.0; opp.ETCV__c = 1.0; opp.x2017__c = 1.0; opp.Product_1_Allocation__c = 100; insert opp; Account_Plan__c ap = new Account_Plan__c(Name ='ABC Account Plan', Account__c = a.Id); insert ap; Revenue_Waterfall__c r = new Revenue_Waterfall__c(account_plan__c = ap.Id,name='Sold Business'); insert r; opp.StageName = '3 - Discovery'; update opp; opp.StageName ='6 - Close/Verbal Award'; update Opp; opp.StageName ='7 - Won'; opp.Reason__c = 'test'; opp.What_did_we_learn__c = 'not sure'; opp.Won_by__c = 'ABC Corp'; update Opp; } }
First you have to use collection to perform DML operations.
Like you create List<Account> accountLst = new List<Account> ();
add Your all account Records and peform DML operation.
Same soldBusinessMethod method create List<Opportunity> and perform DML on Collections.
Create Test Data using @tesetsetup method - https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_testsetup_using.htm
Use Test.startTest & Test.stopTest annotations - https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_tools_start_stop_test.htm
Please mark this as best answer.
Regards,
Prakash
Skype : nawaleprakash