Boundaries on SOQL statements

Ensure all SOQL statements are either bound by either a LIMIT or by a WHERE clause.

Lorenzo Frattini avatar
Written by Lorenzo Frattini
Updated over a week ago


Salesforce limits the  maximum number of rows that can be returned by a SOQL query to 50,000 records. If such number is exceeded, a runtime exception is thrown. As a best practice developers should always use either a WHERE or a LIMIT clause, so  that the maximum number of records retrieved is capped.


  • Apex classes and triggers


  • This rule is not applied to test methods

Did this answer your question?