You need to sign in to do that
Don't have an account?

Using Database.countQuery() throws Warning when >= 500
I'm using the Database.countQuery() passing in a dynamic SOQL statement from a Visualforce page and output the results. For example:
String sSOQL = 'SELECT count() FROM Product2 LIMIT 500';
Integer iRecCount = 0;
iRecCount = Database.countQuery(sSOQL);
ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.INFO, sSOQL));
ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Record Count = ' + iRecCount));
Only when the resulting iRecCount is >= 500 is an apex:pageMessage warning message thrown:
"use countQuery() for [select count()...] queries"
What's unexpected is I am using the countQuery()!
Anyone run into this before? Any solution around it?
Thanks in advance,
Mike
You are counting the queries two times one inside the query and another when call to countQuery
Try this:
String sSOQL = 'SELECT Id FROM Product2 LIMIT 500';
Integer iRecCount = 0;
iRecCount = Database.countQuery(sSOQL);