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
CustomDataIntegrationsCustomDataIntegrations 

Get Record counts in tables

How do I get the total record count from a table (i.e. Account, Lead, Contact)?  I have over 50,000 records in the Lead table.  When I run the query below in my code, it fails with the "Too many query rows: 50001" error.  

LeadRecordCount = [select Count() from lead];



Jason Curtis NBSFDGJason Curtis NBSFDG
This is a pretty common issue, some good documentation/ideas here:http://salesforce.stackexchange.com/questions/843/why-is-the-count-query-in-salesforce-not-counting-the-no-of-query-rows-return

Also, depending on your implmenetation, you might be able to use the @readonly annotation for your class, this can get around some of the limits but it has various limitations of its own, info here: http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#CSHID=apex_classes_annotation_ReadOnly.htm|StartTopic=Content%2Fapex_classes_annotation_ReadOnly.htm|SkinName=webhelp