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

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.