Why is the count() query in salesforce not counting the no. of query rows returned as 1?

Depending on what you're doing, you may be able to use the @ReadOnly annotation to allow queries up to 1 million rows. If this is for a Visualforce component, for example, or a webservice.

If you need this information in a trigger, it will require some kind of workaround, such as storing the total number of Assets in a Custom Setting that's updated every time an Asset is created or deleted.


unlike MySQL, if you look at databases like DB2 or Oracle you (typically) don't get count()'s for free. (let's assume, not going to argue if certain versions of DB2/Oracle 9+ do give this function) I imagine that its the same case here. if you want to know the count you have to scan the table. Scanning the table is going to increment against your limit. I dont see this changing anytime soon (again, assuming that table counts aren't free at the DB level).


Create a summary object, who's sole purpose is to maintain summary counts of the various objects in different configuraitons. Run a batch job every hour to refresh the counts.

Tags:

Soql

Apex