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
SimrinSimrin 

Too many sql queries while executing text class

Hello,

I have below piece of code, which worked well for 1 month and the test class was also sucessful.
Wheni check it again it gevew, Too many sql queries error for a line.
When i execute this line in Execute query then it returns only 15 rows, i have no idea why it fails

List temp = new List();
            try{
temp = [SELECT EFX_Category__c FROM ProfileSkill where EFX_Type__c ='Certifications' ORDER BY EFX_Category__c] ;
            }Catch(DmlException de ){
                System.debug(de);
            } 

 
Best Answer chosen by Simrin
ManojjenaManojjena
Hi Simrin ,

When ar eyou getting this error ? 

If you are getting while executing test class then, 
Please check one thing in your test method may be you don't have Test.startTest() and Test.stopTest() . 
Also one thing you need to change the exception ,as you have simply qury in try block you need to catch QueryException instaed of DmlException .

As your query is not inside for loop ,also you don't have trigger and your code is in class .You need to wrap Test.startTest() and Test.stopTest()  in test methods .

Please let me know if it helps .

Thanks 
Manoj

 

All Answers

Himanshu ParasharHimanshu Parashar
Hi Simrin,

Do you have any SOQL inside trigger?

Thanks,
Himanshu
Tony DeMarcoTony DeMarco
Simrin,

You need to provide more of your code for us to evaluate.  Typically this will occur if you have a Select within a loop.

TDM
SimrinSimrin
there is no trigger for this object
Select is also not in For loop its in If condition but this wont be a loop
Tony DeMarcoTony DeMarco
Are you writing any data that may be firing a trigger on another object?  The code you provided only reads data, so I can't fathom how this is causing your problem unless your code is doing more than what you are showing.
ManojjenaManojjena
Hi Simrin ,

When ar eyou getting this error ? 

If you are getting while executing test class then, 
Please check one thing in your test method may be you don't have Test.startTest() and Test.stopTest() . 
Also one thing you need to change the exception ,as you have simply qury in try block you need to catch QueryException instaed of DmlException .

As your query is not inside for loop ,also you don't have trigger and your code is in class .You need to wrap Test.startTest() and Test.stopTest()  in test methods .

Please let me know if it helps .

Thanks 
Manoj

 
This was selected as the best answer
SimrinSimrin
I slpit the Test classes in to 4. it works after that, strange.
Any reason for this cause.
ManojjenaManojjena
Hi Simrin ,
Not able to catch you properly how you have splited your test class . May be you have added stsrtTest and stopTest in your code .