SOQL Query for the Latest Accounts (ORDER BY and LIMIT)
Return the most recent accounts with ORDER BY and LIMIT, plus OFFSET paging and the null-ordering options most admins never touch.
Updated 2026-09-09
The safest query on a large object is a sorted one with a limit. This is the shape to reach for when you are exploring accounts rather than exporting them.
Accounts sit at the top of most data models, so filters here usually cascade into contact, opportunity, and case reporting.
The query
SELECT Id, Name, Type, Industry, OwnerId
FROM Account
ORDER BY CreatedDate DESC
LIMIT 10Paging with OFFSET
OFFSET caps out at 2,000 rows. Beyond that, page by a filter on the sort field instead of an offset - keyset paging stays fast where OFFSET does not.
SELECT Id, Name, Type, Industry, OwnerId
FROM Account
ORDER BY CreatedDate DESC
LIMIT 10 OFFSET 10Sorting rules worth knowing
ORDER BY field ASC NULLS LASTmoves empty values to the end.- Sorting on multiple fields is allowed:
ORDER BY Status, CreatedDate DESC. - Text sorting follows the org's locale collation, not raw ASCII.
Common mistakes to avoid
- Use the API name
Account, not the UI label - the two differ on several standard objects. - Wrap literal text values in single quotes; date literals such as
LAST_N_DAYS:30must stay unquoted. - Run the query in a sandbox first if it feeds a bulk update - a
WHEREclause that is one character off can select the whole table. LIMITwithoutORDER BYgives you an arbitrary 10 rows, not the newest 10.- Sorting on a non-indexed, high-volume field is the usual cause of a query timeout.
Run it faster with TurboKit
Exploratory queries are throwaway by nature - the value is in getting to the right account in a few iterations.
TurboKit's AI SOQL builder lets you describe the result you want in plain English, returns the query, and exports the rows to CSV or Excel in the same panel - without leaving the Salesforce tab you are already on.
Frequently asked questions
- What is the maximum LIMIT in SOQL?
- The Query API returns rows in batches and pages through them; Apex enforces 50,000 rows per transaction.
LIMITitself accepts values up to 50,000. - Why is my ORDER BY query timing out?
- Sorting a large object on an unindexed field forces a full scan. Add a selective
WHEREclause on an indexed field first - Id, Name, audit dates, and External ID fields are indexed by default. - Does OFFSET work for exporting everything?
- No - it is capped at 2,000. For a full export use the Bulk API or a tool that pages through the query locator for you.
More from the SOQL Library
- SOQL GROUP BY: Accounts by IndustryAggregate SOQL that breaks accounts down by Industry, with COUNT, SUM, and the AggregateResult alias rules.
- SOQL Query for Accounts Created in the Last 30 DaysSOQL for accounts created in the last 30 days, plus the date literals (TODAY, THIS_MONTH, LAST_N_DAYS) that replace hard-coded dates.
- SOQL Query for the Latest Campaigns (ORDER BY and LIMIT)Return the most recent campaigns with ORDER BY and LIMIT, plus OFFSET paging and the null-ordering options most admins never touch.
- SOQL Query for the Latest Cases (ORDER BY and LIMIT)Return the most recent cases with ORDER BY and LIMIT, plus OFFSET paging and the null-ordering options most admins never touch.
- SOQL Query for the Latest Contacts (ORDER BY and LIMIT)Return the most recent contacts with ORDER BY and LIMIT, plus OFFSET paging and the null-ordering options most admins never touch.
- SOQL Query for the Latest Leads (ORDER BY and LIMIT)Return the most recent leads with ORDER BY and LIMIT, plus OFFSET paging and the null-ordering options most admins never touch.
Related reading
- Admin How-ToHow to Write Salesforce Queries Without Knowing SOQL (AI SOQL)Describe the records you want in plain English and get a runnable SOQL query back - how AI SOQL builders work, what to check before you run the result, and where they still fall short.
- GlossaryWhat Is a Salesforce ID in Salesforce?A Salesforce ID is the unique identifier of a record. It comes in a 15-character case-sensitive form and an 18-character case-insensitive form that is safe fo
- GlossaryWhat Is an AI SOQL Builder in Salesforce?An AI SOQL builder turns a plain-English description of the records you want into a runnable SOQL query, using the schema of the org you are working in so the
- GlossaryWhat Is SOQL in Salesforce?SOQL (Salesforce Object Query Language) is the query language used to read records from Salesforce objects. It resembles SQL's SELECT statement but traverses