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 account records



How to find the count of account records if there are more than 2 lakh records?





Hi Malar,


we cannot get the count if org has more than 50000 records, we will get Too many query rows exception.

Idea is we need to break the calls. 


it is possible through the VF Page workarounds.

also I have got other work around in vf page using JavaScript Query.

try this.

put the below code in your vf page. you can see the count of records, if this workaround will work for you, pass the value to your controller. 



<apex:page  >

 <script type="text/javascript">
  var __sfdcSessionId = '{!GETSESSIONID()}';
 <script src="../../soap/ajax/22.0/connection.js"
  <script type="text/javascript"> 
  window.onload = setupPage;

   function setupPage() {
     var state = { 
     output : document.getElementById("output"),
     startTime : new Date().getTime()};
     var callback = {onSuccess: layoutResults,onFailure: queryFailed,source: state};
     sforce.connection.queryAll("Select Id, Name From Account ",callback);
  function queryFailed(error, source) { 
   source.output.innerHTML = "An error has occurred: " + error;
  function layoutResults(queryResult, source) {
    output = queryResult.size +" ";
    source.output.innerHTML = output;
<div id="output"> </div>