+ Start a Discussion

System.LimitException: Too many SOQL queries



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..






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


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 :





Ankit Arora

Blog | Facebook | Blog Page


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.




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.