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
Maverick123Maverick123 

Too many SOQL's: 101 error

Hello Everyone,

 

I have a unique problem, my org has more then 100 testclasses and every deployment takes around ~1.5 hrs. The issue is at times we face a lot of "Too many SOQL's" error. When we try to run these testclasses in our sandbox they run fine, but only during the deployment they crop up.

 

We do take care of coding practises and make sure that there are no queries within the loops and as well as to limit the dml statements...

 

My question is what could be the possible root cause for this? Is there are standard way to streamline these many testclasses? or monitor there governor limit usage(i know we could find them in the debug logs) during run time?

 

Please advice.

 

Thanks,

Maverick

Best Answer chosen by Admin (Salesforce Developers) 
Damien_Damien_

Sorry for the slow response.... I've been on vacation the past week or so.

 

I would like to know, if we call our parent class from testclass that is wrapped in Test.Starttest() and Test.Stoptest(), will it be helpful??

Yes, It will be helpful.  The governor limits inside of your class will be reset at this point.

All Answers

AmitSahuAmitSahu

Have you seen the line where it fails ? 

steve456steve456

Faced this issue a couple of weeks back

 

Just see which test class is causing it

 

Go to that test class

 

and use   Test.startTest();

 

Test.stopTest();

 

so that you can null out your error

Damien_Damien_

It sounds like at least 1 of 2 things may be happening.

 

Are you creating your own test data or running queries in order to get test data?  You should always create your own test data instead of query for existing.

 

Do you have any queries inside of a loop?  You can use Maps to get around doing this.

 

steve456steve456

Change your version of Apex classes to 23.0

 

 

or

 

Add "Seealldata= true" along with test method to retrieve live data from production or sandbox. 

Damien_Damien_

Add "Seealldata= true" along with test method to retrieve live data from production or sandbox.

This is generally a bad practice, and this happening is most likely what is causing his error.  If you are running tests, you should be creating your own test data whenever possible, not relying on existing correct data to be there.

Maverick123Maverick123

Hello All,

 

Thanks for you replies...

 

@Damien_ --> we do create our own data and do not query for the existing data for testclass execution. The problem is we have huge amount of code per object (classes/triggers)..mostly on Account and Opportunity which causes too much of soql processing....

 

I would like to know, if we call our parent class from testclass that is wrapped in Test.Starttest() and Test.Stoptest(), will it be helpful??

 

Thanks,

Maverick

Damien_Damien_

Sorry for the slow response.... I've been on vacation the past week or so.

 

I would like to know, if we call our parent class from testclass that is wrapped in Test.Starttest() and Test.Stoptest(), will it be helpful??

Yes, It will be helpful.  The governor limits inside of your class will be reset at this point.

This was selected as the best answer
Maverick123Maverick123

Thanks Damien_......

sruthiforcesruthiforce
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

 Hi im also facing same problem in my trigger  Too many SOQL's: 101 error

trigger CaseSupportHandlingNotesOnCreate on Case (before insert, before update) {
  set<Id> accIds=new set<Id>();
  if(trigger.isBefore){
    for(Case cTemp:trigger.new){
      accIds.add(cTemp.AccountId);
    }
    if(accIds.size()>0){
      Map<Id,Account> accMap=new Map<Id,Account>([select id,Support_Handling_Notes_del__c,Authorizations_Specializations__c from Account where Id IN:accids]);   if(accMap!=null && accMap.size()>0){
        for(Case temp:trigger.new){
          if(accMap.containsKey(temp.AccountId)){
            temp.Support_Handling_Notes__c=accMap.get(temp.AccountId).Support_Handling_Notes_del__c;
            temp.Account_Authorization__c=accMap.get(temp.AccountId).Authorizations_Specializations__c;/

       }
      }
    }  
  }