Even when you use count() (and you're not returning the rows), I think you're still tied to the governor's limits. So if you're trying to execute that query within a trigger, you'll get that exception if you have over 1000 records (this value scales depending on your batch size). If you're running it within an Apex controller or anonymous code, then your query can contain at most 10000 records before you get that exception.
I had a similar requirement (calculate counts of different objects) and I ended up leveraging Batch Apex to achieve my goal.
Take a look at the Apex documentation on page 155. The section you're interested in is named "Using State in Batch Apex" and it also has a sample code :Apex doc
Integer i = [select count() from Account];
This quary cause the violation... :-(
Its does not works for 25,000 accounts...
have you tried this
Even when you use count() (and you're not returning the rows), I think you're still tied to the governor's limits. So if you're trying to execute that query within a trigger, you'll get that exception if you have over 1000 records (this value scales depending on your batch size). If you're running it within an Apex controller or anonymous code, then your query can contain at most 10000 records before you get that exception.
I had a similar requirement (calculate counts of different objects) and I ended up leveraging Batch Apex to achieve my goal.
What gave you done? how can you count the objects usong Batch Apex?
Thanks!
Take a look at the Apex documentation on page 155. The section you're interested in is named "Using State in Batch Apex" and it also has a sample code :Apex doc