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

Count of more than 50,000 Records



I need to count the TOTAL Record of Account Object using SOQL and display the record count in the Visualforce page, I am already having more than 50,000 records. How can I get the record count and display the total record count in VF Page? Is there is any other way to get the count in Vf page?





Integer ab = [Select count() from Account ];


Use this integer in VF Page .








Ankit AroraAnkit Arora

Dam!! How can i missed that,


Here is the code :


List<AggregateResult> ag = [select count(id) total from account ] ;
System.debug(' :::: ' + ag[0].get('total')) ;



Ankit Arora

Blog | Facebook | Blog Page


I am getting the following error "System.LimitException: Too many query rows: 50001?" , when the record count is more than 50000, so what i need to do to get the exact record count in VF Page(When it is more than 50,000). 





Unfortunately, the aggregate functions are still crippled by the standard SOQL query limits on the number of records retrieved. Even though you are really only bringing back one "row" of data, you are still dinged for every record that makes up that count.


See the note on this page of the Apex docs.

Sonu Sharma.ax1610Sonu Sharma.ax1610




I am also getting the same error.


I would like to count number of records over 50k but i am getting "System.LimitException: Too many query rows: 50001".


Can any one provide some suggestion to count number of records



Sonu Sharma



Nishant sinhaNishant sinha

If you only want to display the count, thne you can use @Readonly annotation.

Sowjanya VaddiSowjanya Vaddi
Too many query rows: 50001--I place LIMIT but still same error,Please suggest to resolve this