Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7722519
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:11:50+00:00 2026-06-01T04:11:50+00:00

I have a Visualforce page where I’d like to display a count of the

  • 0

I have a Visualforce page where I’d like to display a count of the number of records in a particular sObject table.

In the Visualforce page I’d have something fairly simple, like:

<p>Client Account Count: {!ClientAccountCount}</p>

Then in the controller:

// Return the number of clients
public integer getClientAccountCount() {
    return [Select count() from Account where SomeCustomField__c = 'Client' limit 50000];
}

I thought with the limit clause in the SOQL I’d be fine as it would only every return a maximum of 50,000. However, in practice I still get this exception in the production org:

09:29:12:179 SOQL_EXECUTE_BEGIN [108]|Aggregations:0|select count() from Account where SomeCustomField__c = ‘Client’ limit 50000

09:29:12:331 EXCEPTION_THROWN [108]|System.LimitException: Too many query rows: 50001

Is there a safe way to perform this query that won’t result in an exception that I can’t catch?

Oddly, if I try the following as anonymous apex in production it works just fine and returns 50,000.

integer count = [select count() from Account where SomeCustomField__c = 'Client' limit 50000];

Perhaps the issue is the cumulative number of query rows across all operations that is causing the problem and I need to check the Limits in code before running the query?


There is a similar post on the Force.com discussion boards – Too many query rows on COUNT(*) function. I can’t set the VF page to read only to increase the query row limit.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T04:11:52+00:00Added an answer on June 1, 2026 at 4:11 am

    Doh! I’m pretty sure I need to check the cumulative number of records retrieved by SOQL queries for the request. So while one SOQL query could get up to 50,000 records two can’t do 50,000 each.

    Guess I can use Limits.getQueryRows() and Limits.getLimitQueryRows() to disable the SOQL querys if required.


    I’ve changed the way the getClientAccountCount() method works. I figure it is only every going to be able to give an indication of how many rows there are as the aggregate functions are being limited.

    // Return the number of ad book clients
    public string getClientAccountCount() {
        System.debug(LoggingLevel.Debug, 'getClientAccountCount() - Current Query Rows: ' + Limits.getQueryRows() + '/' + Limits.getLimitQueryRows());
        integer recordCount = [Select count() from Account where SomeCustomField__c = 'Client' limit 1001];
        if(recordCount == 1001) { return '1000+'; }
        return string.valueOf(recordCount);
    }
    

    This idea – Count the SOQL count() query as a single row query seems worth promoting.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an HTML table setup in a visualforce page with some functionality that
have 2 questions : A computer with 32-bit address uses 2-level page table (9
I have a custom component in my visualforce page, it requires an attribute :
I have a client who has a custom visualforce page that is embedded on
We have a custom Visualforce page that is within the Account page layout. This
I have created a custom visualforce page. Here in the controller class i want
I have created a custom visualforce page. Here in the controller class i allow
I have a Visualforce page using a custom controller that is used to edit
I have a property that is tied to an SObject like so: public Decimal
I have a visualforce page which is rendering correctly. There is a commandbutton Save

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.