SOQL Query for Leads Created in the Last 30 Days

SOQL for leads created in the last 30 days, plus the date literals (TODAY, THIS_MONTH, LAST_N_DAYS) that replace hard-coded dates.

Updated 2026-09-09

Date-literal filters are the difference between a query you rewrite every month and one you save once. This page covers the lead version and the literals worth memorising.

Leads are high-churn: they are created by campaigns, converted, and archived, so almost every lead query wants a date or status filter.

The query

LAST_N_DAYS:30 is evaluated against the running user's time zone, so the same saved query keeps working tomorrow.

Leads from the last 30 days
SELECT Id, Name, Company, Status
FROM Lead
WHERE CreatedDate = LAST_N_DAYS:30
ORDER BY CreatedDate DESC
LIMIT 200

Other date literals that work here

Month-to-date variant
SELECT Id, Name, Company, Status
FROM Lead
WHERE CreatedDate = THIS_MONTH
ORDER BY CreatedDate DESC
  • TODAY, YESTERDAY, THIS_WEEK, THIS_MONTH, THIS_QUARTER, THIS_YEAR
  • LAST_N_DAYS:n, NEXT_N_DAYS:n, LAST_N_MONTHS:n
  • An explicit range: CreatedDate >= 2026-01-01T00:00:00Z AND CreatedDate < 2026-02-01T00:00:00Z

Filter on LastModifiedDate instead

CreatedDate tells you when the record entered Salesforce. For leads, LastModifiedDate is usually the date the business actually cares about.

By LastModifiedDate
SELECT Id, Name, Company, Status
FROM Lead
WHERE LastModifiedDate = LAST_N_DAYS:30
ORDER BY LastModifiedDate DESC

Common mistakes to avoid

  • Use the API name Lead, 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.
  • Date literals are never quoted. WHERE CreatedDate = 'LAST_N_DAYS:30' fails with a malformed-query error.
  • CreatedDate is a dateTime; comparing it to a plain 2026-01-01 date value silently shifts the boundary by your time-zone offset.

Run it faster with TurboKit

Recency filters are the most re-run queries an admin owns, which is why saving and re-running them matters more than writing them once.

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

Is LAST_N_DAYS:30 the same as the last calendar month?
No. LAST_N_DAYS:30 is a rolling 30-day window ending today, and it excludes today's records in some contexts. LAST_MONTH is the previous calendar month.
Can I filter Lead on a custom date field the same way?
Yes. Date literals work on any Date or DateTime field, standard or custom - just use the field's API name, including the __c suffix.
Why do I get records outside my window?
Date literals resolve in the running user's time zone. If your user's locale differs from the org default, the boundaries move by the offset between them.

More from the SOQL Library

Related reading