Too Many SOQL Queries: 101

Hi all,

I'm receiving the "Too Many SOQL Queries: 101" error. Last time I saw this, I had my SOQL statement w/in a FOR, but I'm not exactly sure what is going on this time. Any help/schooling on the topic is greatly appreciated.

Making SOQL calls from get methods is not a good idea in general. If you have bound these methods to Visualforce page, it's possible that they are getting invoked multiple times. Consider storing method result in an instance variable and check to see if the variable is null before you make SOQL calls. Hope this helps!

Its hard to debug the issue with just that snippet of code. From the looks of it, there is nothing wrong with the code that you posted (i.e. it follows general governor limits best practices). You'll need to explain the entire transaction - i.e.. where is this class called from, are the 'getPlansToReset' or 'getPlansToReset' methods invoked from inside a for loop etc.

Remember that the governor limit of 100 SOQL queries applies across the entire transaction. In other words, if you're doing some SOQL queries in an 'upstream' class (i.e.. a class that invokes the resetQuarterlyDistCount) those will count against the 100 limit. The best way to debug this is to look at the debug logs closely and trace where all the SOQL queries are happening (some of which may be happening before of this class is even invoked).

Hope this helps.

p.s. Though this has nothing to do with the error that you're getting a more efficient SOQL query would be :

I just saw the previous reply by 'gm_sfdc_powerde' and that prompted a closer look at the code. I hadn't noticed before that getPlansToReset was an accessor method for the PlansToReset List variable. gm_sfdc_powerde is correct - it is bad practice to include SOQL queries in get methods since they can be called multiple times during the rendering/re-rendering of a VF page. If this class is indeed a custom controller for a VF page, then follow the advise in gm_sfdc_powerde reply.

If this class is not used in the context of a VF page then you can look at my earlier reply. Hope this helps!

Since the results are cached, this will reduce the total number of SOQL queries to one for the entire set of calls, no matter how many times it is called. An optional parameter allows you to recache the list when necessary (say, after a DML operation that could potentially affect the list).