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.
SELECT Id, Name, Type, Status
FROM Campaign
WHERE CreatedDate = LAST_N_DAYS:30
ORDER BY CreatedDate DESC
LIMIT 200Other date literals that work here
SELECT Id, Name, Type, Status
FROM Campaign
WHERE CreatedDate = THIS_MONTH
ORDER BY CreatedDate DESCTODAY,YESTERDAY,THIS_WEEK,THIS_MONTH,THIS_QUARTER,THIS_YEARLAST_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.
SELECT Id, Name, Type, Status
FROM Campaign
WHERE StartDate = LAST_N_DAYS:30
ORDER BY StartDate DESCCommon 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: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. - Date literals are never quoted.
WHERE CreatedDate = 'LAST_N_DAYS:30'fails with a malformed-query error. CreatedDateis a dateTime; comparing it to a plain2026-01-01date 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:30is a rolling 30-day window ending today, and it excludes today's records in some contexts.LAST_MONTHis 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
__csuffix. - 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
- SOQL GROUP BY: Campaigns by TypeAggregate SOQL that breaks campaigns down by Type, 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 Campaigns Modified TodaySOQL for campaigns changed today, including LastModifiedBy, audit-field filters, and how to spot integration-driven updates.
- SOQL Query for Cases Created in the Last 30 DaysSOQL for cases created in the last 30 days, plus the date literals (TODAY, THIS_MONTH, LAST_N_DAYS) that replace hard-coded dates.
- SOQL Query for Contacts Created in the Last 30 DaysSOQL for contacts created in the last 30 days, plus the date literals (TODAY, THIS_MONTH, LAST_N_DAYS) that replace hard-coded dates.
- SOQL Query for Leads Created in the Last 30 DaysSOQL for leads created in the last 30 days, plus the date literals (TODAY, THIS_MONTH, LAST_N_DAYS) that replace hard-coded dates.
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 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