You need to sign in to do that
Don't have an account?

SOQL Governor Limits Exception Error When using Apex Controller
HI,
I have to write code that takes a list of of International CLubs and calculates a forecast registration count per each member of that club for a grand total. My problem is that I am facing governor limits on a simple query but it does return roughly 4K records before being fed into an Apex Controller to display 300 records per page. What can I do to avoid hitting these limits? Do I need to Bulkify more? How? Here is the code and thanks much for your help (I have highlighted the SOQL statement in Bold ):
public class AccountsCTRL_New { String CountryName = ''; Boolean NextClick = false; Boolean PrevClick = false; // public List<Account> ClubberAccounts = new List<Account>(); public PageReference churchInfo() { try { NextClick = false; prevClick = false; CountryName = Apexpages.currentPage().getParameters().get('name'); } catch(Exception e) { ApexPages.addMessages(e); } return null; } public ApexPages.StandardSetController setCon { get { if(setCon == null) { List<account> accountList = new List<Account>(); setCon = new ApexPages.StandardSetController(accountList); } else { if(CountryName != '' ) //BELOW IS THE PROBLEM SOQL STATEMENT { if( NextClick == false && PrevClick == false) setCon = new ApexPages.StandardSetController(Database.getQueryLocator( [SELECT Id, Name, Territory__c, Mailing_City__c, ClubberCount__c, Mailing_Address_Book__c, ccountTest__c, Type FROM Account WHERE Territory__c =: CountryName AND Customer_Type__c =: 'International Church' ])); } setCon.setPageSize(300); } return setCon; } set; } public List<Account> getAccounts() { return (List<Account>) setCon.getRecords(); } public PageReference PrevList() { if(setCon.getHasPrevious()){ setCon.previous(); PrevClick = true; } return null; } public PageReference NextList() { if(setCon.getHasNext()){ setCon.next(); NextClick = true; } return null; } }
The problem to reduce governor limits was solved by removing the Apex Controller property thatincluded the query and placing the query within a new Page Reference method called "Search". The controller object is just an empty property:
So the solution is: