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
SurenderSurender 

System.LimitException: Too many SOQL queries

Hi,

 

I'm getting System.LimitException in the test case for the below query.

 

User sender = [SELECT Email from USER where Id =: thisOppty.OwnerID];

 

But the above query returns only one record.

 

Need your suggestions to resolve the above..

 

 

 

 

MattLacey.ax1065MattLacey.ax1065

Going out on a limb here, but is this code inside a trigger?

SurenderSurender

This is inside a controller class..

 

Ankit AroraAnkit Arora

Query is returning you one record which is fine, but the error says you are using this query multiple times (more than 100). Make sure this query is not in loop and if you are using trigger you are handling the bulk case.

 

This link will help you for sure :

 

http://wiki.developerforce.com/page/Apex_Code_Best_Practices

 

Thanks

Ankit Arora

Blog | Facebook | Blog Page

MattLacey.ax1065MattLacey.ax1065

I think you're going to have to post the code for anyone to be able to help you here — definitely sounds like you're doing your query in a loop.

 

Chamil MadusankaChamil Madusanka

Yeah, The reason can be "query inside a loop". If you post your code we can help you. And also refer follwoing link to understastand the best practice of Apex coding.

 

http://wiki.developerforce.com/page/Apex_Code_Best_Practices

 

If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

Abrar Ul HaqAbrar Ul Haq

If You are receiving one record that is fine but if you are using this SOQL query in for loop then it will only process 100 records and after that it will say "Too many SOQL queries". you have to use this query outside the for loop by using Map Collection.