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
michael.vomichael.vo 

caused by: System.LimitException: Too many SOQL queries: 101

 

I have the following custom controller class. I get the error when I have 50 or more records and it works fine with less than 50. In the constructor I do this:

 

public Constructor {

 

filteredOpportunities = [select zone__c, Opportunity.Account.Last_Name__c, Opportunity.Account.First_Name__c, SortReservationTime__c, restaurant__c, Covers_Purchased__c, Reservation_Time__c, name, Reservation_note__c, id, AVTablenumber__c, coatcheck__c, primary_acct_name__c, notes__c, c_s_d__c, coversdined__c, numberOfTaxisNeeded__c, time_arrive__c, time_sat__c, time_finished__c, no_show__c, aviary_ticket__c, tix_site_total_price__c from opportunity where Date__c = TODAY and Opportunity.RecordType.name = 'Reservation' and Covers_Purchased__c > 0 and restaurant__c = 'Aviary' Order By SortReservationTime__c ASC, Opportunity.Account.Last_Name__c ASC];

 

for (Opportunity opp : filteredOpportunities) {

    filteredOpportunityWrappers.add(new OpportunityWrapper(opp)); }

 

this.controller = new ApexPages.StandardSetController(this.filteredOpportunities);

 

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
KodiKodi
Hi michale.vo,

Don't write SOQL query in Constructor becoz this is a salesforce best practice. so to avoid query in constructor that's why error will be throw.

All Answers

hitesh90hitesh90

Hi Michael,

 

can you please share your full controller code here?

 


Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator & Advanced Administrator & Sales cloud consultant
My Blog:- http://mrjavascript.blogspot.in/

KodiKodi
Hi michale.vo,

Don't write SOQL query in Constructor becoz this is a salesforce best practice. so to avoid query in constructor that's why error will be throw.
This was selected as the best answer
michael.vomichael.vo

Thanks I commented out that part in the constructor and it works.

 

In the get method for List<Opportunity> I was re-doing the same thing as in the constructor.

KodiKodi

Hi michael,

 

Yes, if u want to display opportunity list means using get method,

 

List<Opportunity> Opp;

public List<Opportunity> getOpp()

{

Opp = [select ..............];

return Opp;

}