You need to sign in to do that
Don't have an account?
XXX
How Do I Get A Record Count?
Using the sample code from the Apex Language reference, I am trying to find out how many Contact records I have:
Integer contactCount = [SELECT COUNT() FROM Contact];
This raises an error "Too many query rows: 501" -- which implies that I cannot get a simple rowcount on tables with more than 500 rows. Is this true? Do I actually have to use a loop and queryMore() to find out how many rows I have in a table?
TIA,
John
All Answers
Maybe this call combined with an integer variable?
queryMore()
Retrieves the next batch of objects from a query().
Syntax
Usage
Use this call to process query() calls that retrieve a large number of records (by default, more than 500) in the result set. The query() call retrieves the first 500 records and creates a server-side cursor that is represented in the queryLocator object. The queryMore() call processes subsequent records in up to 500-record chunks, resets the server-side cursor, and returns a newly generated QueryLocator. To iterate through records in the result set, you generally call queryMore() repeatedly until all records in the result set have been processed (the Done flag is true). You can change the maximum number of records returned to up to 2,000. See Changing the Batch Size in Queries for more information.
Isn't the querymore() for the API calls?
How do you get a count() using SOQL in APEX?
I have a large database and I get errors when I reach 50001 rows using For SOQL loops.
I came across this need as well, and have constructed a solution:
Depending on your needs, you may prefer the dynamic dml solution vs the traditional (soql) solution.
//Method 1
string soql='select count(id) from Case';
AggregateResult res = Database.Query(soql);
Integer count = integer.valueof(res.get('expr0'));
//Method 2
AggregateResult res = [select count(id) from Case];
Integer count = integer.valueof(res.get('expr0'));
Props:
http://boards.developerforce.com/t5/forums/replypage/board-id/apex/message-id/15550
Cheers,
-Kevin
when i hit on a go button for All Accounts view, is there a way i can get the total record count of the accounts somewhere on the page like Previous Next