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];
}
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.
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?