SOQL Query for Campaigns Created in the Last 30 Days

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

Campaign records are low volume but heavily rolled up, so aggregate queries here are cheap and safe to run in production.

The query

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

Campaigns from the last 30 days
SELECT Id, Name, Type, Status
FROM Campaign
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, Type, Status
FROM Campaign
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 StartDate instead

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

By StartDate
SELECT Id, Name, Type, Status
FROM Campaign
WHERE StartDate = LAST_N_DAYS:30
ORDER BY StartDate DESC

Common mistakes to avoid

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