SOQL Query for the Latest Opportunities (ORDER BY and LIMIT)

Return the most recent opportunities 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 opportunities rather than exporting them.

Opportunity queries feed pipeline reviews, so they nearly always combine a stage filter with a close-date window.

The query

10 most recent opportunities
SELECT Id, Name, StageName, Amount, CloseDate
FROM Opportunity
ORDER BY CreatedDate DESC
LIMIT 10

Paging 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.

Page two
SELECT Id, Name, StageName, Amount, CloseDate
FROM Opportunity
ORDER BY CreatedDate DESC
LIMIT 10 OFFSET 10

Sorting rules worth knowing

  • ORDER BY field ASC NULLS LAST moves 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 Opportunity, 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:30 must stay unquoted.
  • Run the query in a sandbox first if it feeds a bulk update - a WHERE clause that is one character off can select the whole table.
  • LIMIT without ORDER BY gives 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 opportunity 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. LIMIT itself 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 WHERE clause 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

Related reading