+ Start a Discussion
karthic sankar 9karthic sankar 9 

Line: 772, Column: 1 System.LimitException: Too many SOQL queries: 101

Please help to resolve my error.


Line: 772, Column: 1
System.LimitException: Too many SOQL queries: 101

My method

public class ViewQAAMController {

public void queryOperation()
    {
        String weekData = '20/07/2020 - 24/07/2020';
        list<String> lstSplitDate1 = new list<String>();
        lstSplitDate1.clear();
        lstSplitDate1 = weekData.split(' - ');
        for(String s : lstSplitDate1)
        {
            System.debug('The date is '+s);
        }
        
        list<QAAM_Weekly_Planner__c> queryData = [select Week_Start_Date__c, Availability__c, ReasonAvailability__c, Work_Hours__c, Pre_Vet_Reviews__c, BAU_File_Reviews__c, Debriefs__c, File_Selection__c, Other_work__c, Other_work_Estimate__c, Total_Work_Time__c, Team_Meeting__c, Huddle__c, Quarterly_Updates__c, Governance_Forums__c, Performance_Reviews__c, Tea_Breaks__c, CPD_e_Learning_Maintenance__c, Coaching__c, PD_Days__c, One_on_Ones__c, Weekly_Tracker_preparation__c, Business_Communications__c, Other__c, Other1__c, Other2__c, Project_Time__c, Other_Time__c, Project_Time_Description__c, Other_Time_Description__c, Shrinkage_time__c, Available_Time__c, Availability_Checking__c, id, Week__C from QAAM_Weekly_Planner__c where Week__C =: weekData];
        list<String> weekDataStatic = new list<String>{'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'};
            integer i=0;
        for(QAAM_Weekly_Planner__c q : queryData)
        {
            
    AvailabilityMap.put(weekDataStatic[i], q.Availability__c);
     //Availabity Map
    CommentsMap.put(weekDataStatic[i], q.ReasonAvailability__c);
     WorkHoursMap.put(weekDataStatic[i], q.Work_Hours__c);
    //Core Categories Map
     EmpMap.put(weekDataStatic[i], q.Pre_Vet_Reviews__c);
     BAUFileReviewsMap.put(weekDataStatic[i], q.BAU_File_Reviews__c);
     DebriefsMap.put(weekDataStatic[i], q.Debriefs__c);
     FileSelectionMap.put(weekDataStatic[i], q.File_Selection__c);
     OtherworkMap.put(weekDataStatic[i], q.Other_work__c);
     OtherworkEstimation.put(weekDataStatic[i], q.Other_work_Estimate__c);
        TotalWorkTime.put(weekDataStatic[i], q.Total_Work_Time__c);
    //Shrinkage Categories Map
     TeamMeetingMap.put(weekDataStatic[i], q.Team_Meeting__c);
     HuddleMap.put(weekDataStatic[i], q.Huddle__c);
     QuarterlyUpdatesMap.put(weekDataStatic[i], q.Quarterly_Updates__c);
     GovernanceForumsMap.put(weekDataStatic[i], q.Governance_Forums__c);
     PerformanceReviewsMap.put(weekDataStatic[i], q.Performance_Reviews__c);
     TeaBreaksMap.put(weekDataStatic[i], q.Tea_Breaks__c);
     LearningMaintenanceMap.put(weekDataStatic[i], q.CPD_e_Learning_Maintenance__c);
     CoachingMap.put(weekDataStatic[i], q.Coaching__c);
     PDDaysMap.put(weekDataStatic[i], q.PD_Days__c);
     OneonOnesMap.put(weekDataStatic[i], q.One_on_Ones__c);
     WeeklyTrackerpreparationMap.put(weekDataStatic[i], q.Weekly_Tracker_preparation__c);
     BusinessCommunicationsMap.put(weekDataStatic[i], q.Business_Communications__c);
     OtherMap.put(weekDataStatic[i], q.Other__c);
     Other1Map.put(weekDataStatic[i], q.Other1__c);
     Other2Map.put(weekDataStatic[i], q.Other2__c);
     ProjecttimeMap.put(weekDataStatic[i], q.Project_Time__c);
     OthertimeMap.put(weekDataStatic[i], q.Other_Time__c);
    ProjecttimeDesMap.put(weekDataStatic[i], q.Project_Time_Description__c);
    OthertimeDesMap.put(weekDataStatic[i], q.Other_Time_Description__c);
    ShrinkageTimeMonMap.put(weekDataStatic[i], q.Shrinkage_time__c);
    //Available Hours
    AvailMonMap.put(weekDataStatic[i], q.Available_Time__c);
    CheckMonMap.put(weekDataStatic[i], q.Availability_Checking__c);
            i++;
        }
    }

 public void EmpMapSecValues()
    {
        EmpMap_Monday = EmpMap.get('Monday');
        EmpMap_Tuesday = EmpMap.get('Tuesday');
        EmpMap_Wednesday = EmpMap.get('Wednesday');
        EmpMap_Thursday = EmpMap.get('Thursday');
        EmpMap_Friday = EmpMap.get('Friday');
        System.debug(EmpMap_Monday + '-' +EmpMap_Tuesday  + '-' + EmpMap_Wednesday + '-' +EmpMap_Thursday  +'-' +EmpMap_Friday);
    }

}

I call this in 

ViewQAAMController obj = new ViewQAAMController();
obj.queryOperation();
obj.EmpMapSecValues();

and I get the error Line: 772, Column: 1 System.LimitException: Too many SOQL queries: 101

Line 772 is: integer i=0;

Regards
Karthic Sankar V P
WEN JIEWEN JIE
Hi Karthic,

You need to optimize your codes to reduce SOQL.

Thanks.