I am trying to get record count by giving the query
Select count(id) from report where id='xxxxxxxxxxxxxxxxx';
But i am sure if it exceed 1 lakh records, we get limit exception.
Is there any work arround to get count.
Thanks in advance.
1 Answer
Why shouldn't you use database.query(query) instead.
AggregateResult results = database.query('SELECT COUNT(id) result FROM someSObject');
System.debug('No of ids are: '+results.get('result')); // Id are always unique
Using database.countQuery() or [SELECT count() FROM someObject]; hits governor limit if records > 50000
If you can use @readonly in you class then that limit will extend to million.
Also try to filter it with some criteria using WHERE clause, field which have no significant of counting if they have some particular value that doesn't matter.
-
-
Use the Power of One, as mentioned by Salesforce and discussed in this answer.– TanmayCommented Jan 9, 2015 at 11:05
-