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
Shwetal DesaiShwetal Desai 

System.Exception: MediSpa:Too many query rows: 510

My Test Method Class contains almost all APex Code of my application

In one of my many Apexclass i have a reset method which reseting the two lists.

each list has more than 250 records, now how can i limit the query rows

 

my test method gives me error  

 

 System.Exception: MediSpa:Too many query rows: 510

 

Help ! 

 

 

Shwetal 

Best Answer chosen by Admin (Salesforce Developers) 
aalbertaalbert

Are you using the Test.startTest and Test.stopTest methods? In your individual test methods, you can differentiate the context of the governor limit resources by instantiating the startTest method. In more detail, each test method can only query a maximum of 500 records. But any test method code within the startTest and stopTest methods will inherit the governor limits for the Apex context that is invoked - trigger, controller methods, apex web service, ect. For example, if you invoke a trigger within the startTest and stopTest, you will enable trigger related governor limits.

 

There is more information on these two methods in the Introduction to Apex Code Test Methods article too. 

All Answers

aalbertaalbert

Are you using the Test.startTest and Test.stopTest methods? In your individual test methods, you can differentiate the context of the governor limit resources by instantiating the startTest method. In more detail, each test method can only query a maximum of 500 records. But any test method code within the startTest and stopTest methods will inherit the governor limits for the Apex context that is invoked - trigger, controller methods, apex web service, ect. For example, if you invoke a trigger within the startTest and stopTest, you will enable trigger related governor limits.

 

There is more information on these two methods in the Introduction to Apex Code Test Methods article too. 

This was selected as the best answer
Shwetal DesaiShwetal Desai
Thanks Albert,

It works,

Thanks a lot,