You need to sign in to do that
Don't have an account?
Hardik
SOQL count() returns incorrect value
In my application am using a custom object. When I try to fetch the count using "select count()..." it throws the exception - Too many query rows. Whereas Count aggregated function returns me the count 10226 and the same exception, but the custom object has only 660 records.
Is it a bug or am missing something?
Yes, i believe its the problem. You might need to change entire program logic so as to not to allow any sql inside any loop whatsover. Recommends to define map and list items at the top of class, do just one SOQL fetch and use it for rest of program logic by querying on that map/list for processing data into other maps & lists.
see this link on governor limits.
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_gov_limits.htm
All Answers
Hey
Is there a nested query in the main query? Could you post the code please.
Wes
This is the select query:
Integer total = [select count() from MyActivity__c where Activity_Id__c = null and CreatedBy.UserName =: UserInfo.getUserName()];
Actually this issue occur when there are multiple select operations in a single thread. Its like I query some other custom object and in the same thread I also query this custom object on click of a link in the UI. But it works when I invoke only this query separately.
So your controller code has more than one select statement? Try using Limit.getDMLRows class in conjunction with System.debug messages before and after your queries. This will show you how and where you're building up DML rows. Check out the Limit class docs here: http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_limits.htm
Wes
Sorry I must've been half asleep, you should be using the Limit.getQueryRows() class.
You may be running into the default limits on queries which do add up per invocation.
Have you tried explicitly setting the limit on the query [ select fields from table where condition limit 14000 ]
Joel Schaubert
Suggests to run the query outside as-is in Eclipse scema to see if the query is valid and check on limit. ofcourse, hardcode the username that you are trying to find.
My guess is you have ran out of limit on your apex soql limits as you might have some soql within loop. Comment all other parts of your apex to see if it run fine.
Also, check on debugger/system log on what is the running count at the end of log listings.
In a single thread I've multple database calls, is the limit 10K is for total records fetched in a single thread execution or it is based on an indivisual query. As this count keeps growing with the number of Select queries executed in the same thread?
Am actually using the aggregated function MAx multiple times on the custom object with 640 records, If this is how it is, the count will go to 15 * 640 only for the MAX itself and maybe thats the reason its failing.
Putting limit to query will not help as any single query will return maximum 640 records.
Yes, i believe its the problem. You might need to change entire program logic so as to not to allow any sql inside any loop whatsover. Recommends to define map and list items at the top of class, do just one SOQL fetch and use it for rest of program logic by querying on that map/list for processing data into other maps & lists.
see this link on governor limits.
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_gov_limits.htm
You were right, query rows count is thread based. Now am updating my logic accordingly.
Thank you all for your support and the useful links on Salesforce..