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
FilikinFilikin 

Time limit exceeded on a single SOQL statement

Hi,
I have a visual force page that displays the number of records available for processing - a single number with one SOQL statement behind it:

List<aggregateResult> recordsLeft = [select count(ID) toProcess from Assessment__c where Processed_for_SPSS__c = false and Assessment_Date__c > 2006-01-01 ];

I get a time limit exceeded error nine times out of ten when I try to display the page.
Assessment_Date__c is indexed.
I have about 20,000 records
Is there anything I can do to speed this up?
 
Shrikant BagalShrikant Bagal
you can try for Pagination using setController.
FilikinFilikin
I need one number displayed on the page, how pagination would help?
ManojjenaManojjena
Hi Filikin,

Try with below code !!
Integer count =[select count()  from Assessment__c where Processed_for_SPSS__c = false and Assessment_Date__c > 2006-01-01];

Thanks
Manoj
FilikinFilikin
Thanks, but that gave me the same error. I tried adding limit 10000 and that appeared to fix the problem, but this morning I got the timeout error first attempt and it succeeded on the second attempt. I suspect caching somewhere allows it to work sometimes.
FilikinFilikin
Still struggling with this.
the object in question has 497 fields - could this be causing the problem?
FilikinFilikin
Problem back again - last night it took 4 attempts before the query succeeded.
I have raised a case, but I am not hopeful as the initial response was "this is a coding issue, go to the developers forum"
I wait and see...