Salesforce enforces a governor limit of 50,000 records per SOQL query to maintain platform performance and stability. When a query exceeds this
limit, it throws a LimitException: Too many query rows: 50001 error, causing your code to fail.
Unlimited queries pose several risks:
- Runtime failures: Your application will crash when the query returns too many records
- Performance degradation: Large result sets consume more memory and processing time
- Unpredictable behavior: Query results may vary between environments based on data volume
- Resource consumption: Excessive memory usage can impact other operations
This limit is a hard governor limit in Salesforce, meaning it cannot be increased by contacting support. The only solution is to design queries
that respect this constraint from the start.
Queries without LIMIT clauses are particularly risky when:
- Querying large standard objects like Account, Contact, or Lead
- Using broad WHERE conditions that don’t significantly filter results
- Working with custom objects that may grow over time
- Running in production environments with substantial data volumes
What is the potential impact?
Applications will fail with runtime exceptions when queries exceed 50,000 records. This can cause business processes to halt, data synchronization
to fail, and user workflows to break unexpectedly.