+ Start a Discussion
Rakesh SRakesh S 

system.limitException: Too many query rows:50001

Hi All,

i want to get all class dates more than today. But I got the following exception while Controller and test class moving to Production.
     System.limitException: Too many query rows:50001.
User-added image

this is my method:
public List < SelectOption > getClassDate() {
// Error coming below line.
    List < AggregateResult > listOFClassDates = [SELECT Class_Date__c FROM Class_Book__c where Class_Date__c >= Today GROUP BY Class_Date__c];

        List < SelectOption > listOfSelectOption = new List < SelectOption > ();
        listOfSelectOption.add(new Selectoption('0', 'Please Select'));
        for (AggregateResult lb: listOFLogBook) {

            Date dt = (date) lb.get('Class_Date__c');
            dateStr = string.valueOf(dt.month()) + '/' + string.valueOf(dt.day()) + '/' + string.valueOf(dt.year());

            listOfSelectOption.add(new Selectoption(string.valueOf(dt), dateStr));

        }
        return listOfSelectOption;
    }

In production, i got only 100 records for this query like 
[SELECT Class_Date__c FROM Class_Book__c where Class_Date__c >= Today GROUP BY Class_Date__c];

How can i achieve this problem. Any one please help me.

Thank you.
hitesh90hitesh90
Hello Rakesh,

Can you please post your test class here?

Thank You,
Hitesh Patel
Email :- hiteshpatel.aspl@gmail.com
http://mrjavascript.blogspot.in/
Rakesh SRakesh S
Hi,
This is my test class. I got error at " sta.getScheduledDate(); "
@isTest (SeeAllData=true)
public class ControllerTest {
    @isTest (SeeAllData = true) private static void test1()
    {
        
        
        Location__c newLoc = new Location__c();
        newLoc.name = 'Location1';
        newLoc.Address_1__c = 'testAdress';
        newLoc.Address_2__c = 'testAdd2';
        newLoc.Phone_No__c = '7483483443';
        newLoc.City__c = 'testCity';
        newLoc.State__c = 'testState';
        newLoc.Zipcode__c = '34343';
        newLoc.Science_Fee__c = 70;
        newLoc.Math_Fee__c = 80;
        newloc.Social_Fee__c = 100;
        newLoc.English_Fee__c = 100;
        newLoc.Manager__c = UserInfo.getUserId();
        insert newLoc;
        
        Student__c newStudent = new Student__c();
        newStudent.Location__c = newLoc.Id;
        newStudent.Name = 'testStudent';
        newStudent.Last_Name__c = 'testStudent';
        newStudent.Date_of_Joining__c = Date.today();
        insert newStudent;
        
        SubjectRegistered__c newStudentSubReg = new SubjectRegistered__c();
        newStudentSubReg.Student__c = newStudent.Id;
        newStudentSubReg.Subject__c = 'Social';
        newStudentSubReg.Level__c = 'Level 2';
        newStudentSubReg.Week__c = 'A';
        newStudentSubReg.Select_Day__c = 'Monday';
        newStudentSubReg.Select_Date__c = Date.today();
        newStudentSubReg.Start_Time__c = '10:35';
        newStudentSubReg.End_Time__c  = '10:45';
        insert newStudentSubReg;
        
        book__c lb = new book__c();
        lb.Student__c = newStudent.Id;
        lb.Subject__c = 'Abacus';
        lb.Class_Date__c = Date.today();
        lb.SubjectsRegistered__c = newStudentSubReg.Id;
        lb.Level__c = newStudentSubReg.Level__c;
        lb.Week__c = newStudentSubReg.Week__c;
        insert lb;
        
        SubjectRegistered__c newStudentSubReg1 = new SubjectRegistered__c();
        newStudentSubReg1.Student__c = newStudent.Id;
        newStudentSubReg1.Subject__c = 'science';
        newStudentSubReg1.Level__c = 'Level III';
        newStudentSubReg1.Week__c = 'B';
        newStudentSubReg1.Select_Day__c = 'Tuesday';
        newStudentSubReg1.Select_Date__c = Date.today();
        newStudentSubReg1.Start_Time__c = '10:00';
        newStudentSubReg1.End_Time__c  = '12:30';
        insert newStudentSubReg1;
        
        Teacher__c t = new Teacher__c();
        t.City__c = 'NZB';
        t.Country__c = 'India';
        t.Email__c = 'dsfds@gmail.com';
        t.Location__c = newLoc.Id;
        t.Name = 'AAA';
        insert t;
        
        SubjectRegistered__c newStudentSubReg2 = new SubjectRegistered__c();
        newStudentSubReg2.Student__c = newStudent.Id;
        newStudentSubReg2.Subject__c = 'Math';
        newStudentSubReg2.Level__c = 'Level X';
        newStudentSubReg2.Week__c = 'C';
        newStudentSubReg2.Select_Day__c = 'Tuesday';
        newStudentSubReg2.Select_Date__c = Date.today();
        newStudentSubReg2.Start_Time__c = '10:30';
        newStudentSubReg2.End_Time__c  = '11:00';
        newStudentSubReg.Teacher__c = t.id;
        insert newStudentSubReg2;
            
        SubjectRegistered__c newStudentSubReg3 = new SubjectRegistered__c();
        newStudentSubReg3.Student__c = newStudent.Id;
        newStudentSubReg3.Subject__c = 'G.K';
        newStudentSubReg3.Level__c = 'Level IV';
        newStudentSubReg3.Week__c = 'A';
        newStudentSubReg3.Select_Day__c = 'Tuesday';
        newStudentSubReg3.Select_Date__c = Date.today();
        newStudentSubReg3.Start_Time__c = '12:20';
        newStudentSubReg3.End_Time__c  = '01:30';
        insert newStudentSubReg3;
        
        List<SelectOption> test_options = new List<SelectOption>();
        test_options.add(new SelectOption('lb.id', 'AAA'));
        Map<integer,SelectOption> seloptions = new Map<integer,SelectOption>();
              
        ApexPages.StandardController contr = new ApexPages.StandardController(lb);
        TeacherAssignController sta = new TeacherAssignController();
        sta.getListOfStudentForADate();
        sta.assignTeacherToOtherStudent1();
        sta.getTeachersList2Assign();
        sta.getListOfStudentForADate();
        sta.getScheduledDate();
        sta.getTeachersList();
        sta.TeacherId = t.id;
       TeacherAssignController.Teacher tch = new TeacherAssignController.Teacher(t.Id,'asdf');
        sta.storeStudentInfo();
        sta.storeTeacherInfo();
        
        sta.count = 5;
        sta.st='10';
        sta.et='11';
        sta.val='val';
        sta.val1='val1';
        sta.studentinfo='studentinfo';
        list<SelectOption> li= new list<SelectOption>();
        li = sta.TimeOptions1;
        List<String> str = new List<String>();
        str = sta.TimeOptions;
        seloptions = sta.options;
        Set<String> setOfTeacher=new Set<String>();
        sta.getAllTeacherList();
        Date d = sta.teacherAssignmentDate;
        sta.selectedTeacher='aaaa';
               
        map<string, string> mapStudentInfo = new map<string, string>();
         
        Date selectedDate = date.today();
        
        List<Book__c > listOFLogBook = new List<Book__c >();
        List<Book__c> listOfStudent =new List<Book__c>();
       String innerTeacherId=t.Id;
        listOFLogBook = [Select id, Student__R.name,Student__R.Last_Name__c,Student__R.id,Subject__c,Level__c,Week__c,
                                                           SubjectsRegistered__r.Start_Time__c,
                                                           SubjectsRegistered__r.End_Time__c,
                                                           SubjectsRegistered__r.Select_Date__c,
                         SubjectsRegistered__r.Teacher__r.id,SubjectsRegistered__r.Teacher__r.name From Book__c 
                         where Class_Date__c=:selectedDate and ((SubjectsRegistered__r.Teacher__r.id=:innerTeacherId  and TeacherId__c=:null ) 
                                                                          OR TeacherId__c=:innerTeacherId) order by Class_Scheduled_Date__c ASC Limit 1];
          
       
        
        for(Book__c lb1:listOFLogBook){ 
        listOfStudent.add(lb1);
          }
        system.debug('22222 '+listOFLogBook);
        system.debug('3333 '+listOfStudent);
             
    }
}

 
hitesh90hitesh90
Hello Rakesh,

Remove the "(SeeAllData=true)" statement from your rest class. this is not a best practice to write a test class.
remove it and try to deploy it again.

Thank You,
Hitesh Patel
Email :- hiteshpatel.aspl@gmail.com
http://mrjavascript.blogspot.in/