function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Harshad KokaTe 22Harshad KokaTe 22 

InvoicePreviewSingle System.LimitException: TR1:Too many SOQL queries: 101

This is my method of test class which is giving full coverage but while deployment to production its giving an error System.LimitException: TR1:Too many SOQL queries: 101
Stack Trace: (TR1)
For following method:


public static testMethod void InvoicePreviewSingle(){
        
        // Starting Test
        Test.startTest();
        invoiceUtilityListData ();
        test.setCurrentPage(Page.BulkInvoicePreview_v1);
        BulkInvoicePreview_v1 invoicePreview = new BulkInvoicePreview_v1();
        
        
        invoicePreview.recordType = Invoicing_Constants.CONSULTING;
        invoicePreview.timesheet1.TR1__Week_Ending__c = System.today();
        invoicePreview.timesheet.TR1__Week_Ending__c = System.today();
        invoicePreview.InvoiceType = 'Single';
        invoicePreview.invoiceDate = System.today().format();
        invoicePreview.showDisabled = true;
        invoicePreview.statusList.add('Approved');
        
        System.assertEquals(4, accList.size());
        System.assertEquals(accList[0].id ,consultingClosingReport.TR1__Account__c);
        System.assertEquals(2, timesheetList.size());
         System.assertEquals(2,timesheetDetailList.size());
        
        invoicePreview.ContinueRecord();
        
        // Setting the Current Page     
       test.setCurrentPage(Page.BulkInvoice_v1);
        
        ApexPages.CurrentPage().getparameters().put('ids', String.valueOf(accList[0].Id));
        ApexPages.CurrentPage().getparameters().put('closingReportIds', String.valueOf(consultingClosingReport.Id));
        ApexPages.CurrentPage().getparameters().put('invoiceDate', String.valueOf(System.today()));
        ApexPages.CurrentPage().getparameters().put('jobType', Invoicing_Constants.CONSULTING);
        ApexPages.CurrentPage().getparameters().put('weekEndDate', String.valueOf(timesheetList[0].TR1__Week_Ending__c));
        ApexPages.currentPage().getParameters().put('value', String.valueOf(0));
        ApexPages.currentPage().getParameters().put('isPreview', 'true');
        ApexPages.currentPage().getParameters().put('InvoiceType', 'Single');
        ApexPages.currentPage().getParameters().put('isPrint', 'true');
        
        BulkInvoiceController_v1 invoiceCtrl = new BulkInvoiceController_v1();
        System.assertEquals(0, invoiceCtrl.invoiceList.size());
        
        invoicePreview.showInvoices();
        
        invoicePreview.nextList();
        invoicePreview.prevList();
        
        invoicePreview.showDisabled = true;
        invoicePreview.ContinueRecord();
        
        invoicePreview.showInvoices();
        
        // Calling Send Email method
        invoicePreview.SaveAndSendEmail();
        
        invoicePreview.getType();
        invoicePreview.getPeriod();
        invoicePreview.getHasRecords();
        invoicePreview.onChangeFilter();
        invoicePreview.getInvoicingType();
        invoicePreview.getTimesheetStatusOptions();
        
        invoicePreview.updateTimesheets(timesheetList, 'Printed', String.valueOf(System.today()));
        invoicePreview.updatePrintStatus();
        
        //Stopping Test
        Test.stopTest();
               
    }  

 
Hargobind_SinghHargobind_Singh
I suggest distributing your test methods to smaller chunks, and test only one function in one test method, sometimes trying to test the whole class might execute a lot of queries crossing the governor limits. 

its hard to tell looking at your code, but I would suggest refactoring your code and probably test only some functionality in one test. 

Here is some info: 

https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_testing_best_practices.htm


 
harshad kokateharshad kokate
but its working in sand box and not working in production .
how is it  possible ?