0

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 1

1

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.

3

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .