Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.

LIMIT

LIMIT is an optional clause that can be added to a SELECT statement of a SOQL query to specify the maximum number of rows to return.

The syntax for LIMIT is:

1SELECT fieldList
2FROM objectType
3[WHERE conditionExpression] 
4  [LIMIT numberOfRows]

For example:

1SELECT Name
2FROM Account
3WHERE Industry = 'Media' LIMIT 125

This query returns the first 125 Account records whose Industry is Media.

You can use LIMIT with count() as the fieldList to count up to the maximum specified.

You can't use a LIMIT clause in a query that uses an aggregate function, but does not use a GROUP BY clause. For example, the following query is invalid:

1SELECT MAX(CreatedDate)
2FROM Account LIMIT 1