You need to sign in to do that
Don't have an account?
Vaclav Lukasek
Scrash on counting objects over 50000
system.debug([Select COUNT() from XXX__c]);
will raise:
FATAL_ERROR|System.LimitException: Too many query rows: 50001
will raise:
FATAL_ERROR|System.LimitException: Too many query rows: 50001
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_gov_limits.htm
Force.com is a multi-tenant platform, which means that all computing resources are shared across a mutiple tenants. The common analogy is an apartment or condo building. Each tenant has a room, but everyone shares the same infrastructure (plumbing, electrical, landscape, etc). In this case it means the CPU processing time is divided amongst the tenants.
To ensure that one tenant does not consume all the resource and degrade performance for the rest of the tenants, Force.com has a concept called "Governor Limits". These limits ensure that one client does not hog all the resources.
Database queries are some of the most time intensive operations an application can make. Therefore to ensure SFDC is able to transact billions of transaction a day they put the following limits on SOQL queries:
1. No More than 50K results in a resultset.
2. You can't do JOINS like you can in SOQL. You can do a subset of JOIN which SOQL calls Parent and Child Queries.
3. You can only make 100 SOQL queries in a Trigger transaction, 200 in an Batch Transaction.
I hope that helps give more color to David's answer above. All the limits are listed in David's response.
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_gov_limits.htm
function using agregation are not slow if use good concept and each db engine will not consume too much time to get SELECT COUNT() of something , but understand that conditions in this case can be problem
But still how can i get count of all objects if their count is over 50000
Again, SFDC is multitenant platform (https://developer.salesforce.com/page/Multi_Tenant_Architecture). You can still have indexes and still not scale with Indexes. It will still perform a Full Table Scan even with Indexes if they are not selective as defiend by the Force.com Optimizer. Please see this article if you need to understand how indexes work on the Force.com platform. They do not work the same as a SQL DB. database. https://help.salesforce.com/help/pdfs/en/salesforce_query_search_optimization_developer_cheatsheet.pdf
In short you cannot do an Aggregate SOQL like you want to do above on the platform. You need to do selective SOQL queries to filter you dataset to work within the confines of the platform in Apex.
http://www.salesforce.com/docs/en/cce/ldv_deployments/salesforce_large_data_volumes_bp.pdf
Hope that material helps you.
http://www.salesforce.com/us/developer/docs/pages/index_Left.htm#StartTopic=Content/pages_controller_readonly_context.htm
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_annotation_ReadOnly.htm
if(Limits.getQueries() > 50000){
return false;
}else{
return true;
}
}
Use this method before every SOQL so that can know query limit before use the other SOQL Call.