SOQL Query for Tasks Created in the Last 30 Days

SOQL for tasks 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 task version and the literals worth memorising.

Activity data is stored differently from other objects, so tasks reward tight filters and rarely need every field selected.

The query

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

Tasks from the last 30 days
SELECT Id, Subject, Status, Priority
FROM Task
WHERE CreatedDate = LAST_N_DAYS:30
ORDER BY CreatedDate DESC
LIMIT 200

Other date literals that work here

Month-to-date variant
SELECT Id, Subject, Status, Priority
FROM Task
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 ActivityDate instead

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

By ActivityDate
SELECT Id, Subject, Status, Priority
FROM Task
WHERE ActivityDate = LAST_N_DAYS:30
ORDER BY ActivityDate DESC

Common mistakes to avoid

  • Use the API name Task, 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 Task 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