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
minciminci 

Query violattion.

I wrote the query:

 

Select count() from Account

 

I have around 20,000 accounts in the system.

So how am I suppouse to get their number in the system?

Thanks!

Satya.KonaSatya.Kona

Integer i = [select count() from Account];

minciminci

This quary cause the violation... :-(

Its does not works for 25,000 accounts...

lodoss1118lodoss1118

have you tried this

 

String QueryString = 
'SELECT count() FROM Account';
Integer I =
Database.countQuery(QueryString);
JA-DevJA-Dev

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.

minciminci

What gave you done? how can you count the objects usong Batch Apex?

Thanks!

JA-DevJA-Dev

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