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
krishnagkrishnag 

too many query rows 501

can anybody explain me what is this error.I am trying to deploy a contoller class and visualforce page into production and i am geting this error.

 

system.limit.exception:    Too many query rows 501.

Best Answer chosen by Admin (Salesforce Developers) 
krishnagkrishnag

solved the problem i added the test.satrttest() and test.stoptes() and also instantiated the account object so that it took only the test data and deployed it succesfully.

All Answers

Pradeep_NavatarPradeep_Navatar

In my opinion, this error is coming due to the test method. Instead of using single test method, try using two test methods. It seems that the current test method is reaching the query limit.

 

Hope this helps.

bob_buzzardbob_buzzard

Is your test data completely isolated from the existing, real data? I usually see this problem when I've not excluded the existing data and suddenly there are 20000 more accounts than in my dev sandbox!

krishnagkrishnag

u r right Bob thats what happening.I am facing this problem when i tried to deploy its having records more than sandbox

bob_buzzardbob_buzzard

So you'll need to restructure your test to only use data that it has created.  Can you post the code?

krishnagkrishnag

 

public static testMethod void testnurture() {
   
   Profile p = [SELECT Id FROM profile WHERE name='Standard User'];

        User u2 = new User(alias = 'kotha', email='newuser@testorg.com',

                    emailencodingkey='UTF-8', lastname='user',

                    languagelocalekey='en_US',

                    localesidkey='en_US', profileid = p.Id,
                    timezonesidkey='America/Los_Angeles',

                    username='kotha@testorg.com');

        System.runAs(u2) {

            // The following code runs as user u2.

            // Create all your test data here

            // this block will not run in system mode,

            // so access to org level data

            // will be pretty limited
            
            String expectedJSON = '{cols:[{id:"col1",label:"month",type:"string"},{id:"col2",label:"number of registrants",type:"number"},'+'rows:[{c:[{v:1.0},{v:1.0},{v:1.0},{v:1.0}]}]}';
   String expectedJSON1 = '{cols:[{id:"col1",label:"week",type:"string"},{id:"col2",label:"number of registrants",type:"number"},'+'rows:[{c:[{v:1.0},{v:1.0},{v:1.0},{v:1.0}]}]}';
   String expectedJSON2 = '{cols:[{id:"col1",label:"",type:"string"},{id:"col2",label:"this month",type:"number"},{id:"col3",label:"compare last month",type:"number"},{id:"col4",label:"this week",type:"number"},{id:"col5",label:"compare",type:"number"}'+'rows:[{c:[{v:"D&O"},{v:1.0},{v:1.0},{v:1.0},{v:0.0}]}]}';
   
   Account a = new Account(RecordTypeId ='01280000000Pxf7',name='testaccount',HelpPoint_Delivered__c = true,Company_Relationship__c = 'Prospect',Relationship_Type__c = 'Activity',Lead_Created_Date__c = System.Today());
   //Account b = new Account(RecordTypeId ='01280000000Pxf7',name='testaccount2',HelpPoint_Delivered__c = true, Company_Relationship__c = 'Broker',Lead_Created_Date__c = System.Today().addDays(-7));
  // Account c = new Account(RecordTypeId ='01280000000Pxf7',name='testaccount3',HelpPoint_Delivered__c = true,Company_Relationship__c = 'Employee',Lead_Created_Date__c = System.Today());
  // Account d = new Account(RecordTypeId ='01280000000Pxf7',name='testaccount4',HelpPoint_Delivered__c = true,Company_Relationship__c = 'Customer',Relationship_Type__c = 'Current',Lead_Created_Date__c = System.Today());
 insert a;
 //insert b;insert c;insert d;
 
 nurture nur = new nurture();
 nur.getLeadsbymonth();
 nur.getLeadsbyweek();

 
 String actualJSON = nur.getLeadsbymonth();
 String actualJSON1 = nur.getLeadsbyweek();
 String actualJSON2 = nur.getAppetites();

            
             

        }

   
   
   }

 

 

krishnagkrishnag

solved the problem i added the test.satrttest() and test.stoptes() and also instantiated the account object so that it took only the test data and deployed it succesfully.

This was selected as the best answer