In SOQL, you can use different date literals in the WHERE clause to filter records based on date ranges. Here are some alternatives to THIS_YEAR:

Common Date Literals:

Date Literal Description
TODAY Records created today
YESTERDAY Records created yesterday
TOMORROW Records created tomorrow
LAST_WEEK Records created in the last week (Sunday to Saturday)
THIS_WEEK Records created in the current week (Sunday to Saturday)
NEXT_WEEK Records created in the next week (Sunday to Saturday)
LAST_MONTH Records created in the last month
THIS_MONTH Records created in the current month
NEXT_MONTH Records created in the next month
LAST_90_DAYS Records created in the last 90 days
NEXT_90_DAYS Records created in the next 90 days
LAST_YEAR Records created in the previous year
NEXT_YEAR Records created in the next year
THIS_QUARTER Records created in the current quarter
LAST_QUARTER Records created in the previous quarter
NEXT_QUARTER Records created in the next quarter
LAST_N_DAYS:n Records created in the last n days (e.g., LAST_N_DAYS:30)
NEXT_N_DAYS:n Records created in the next n days
LAST_N_WEEKS:n Records created in the last n weeks
NEXT_N_WEEKS:n Records created in the next n weeks
LAST_N_MONTHS:n Records created in the last n months
NEXT_N_MONTHS:n Records created in the next n months
LAST_N_YEARS:n Records created in the last n years
NEXT_N_YEARS:n Records created in the next n years

Example Queries:

1️⃣ Accounts created in the last 30 days

SELECT Id, Name, CreatedDate
FROM Account
WHERE CreatedDate = LAST_N_DAYS:30

2️⃣ Accounts created last year

SELECT Id, Name, CreatedDate
FROM Account
WHERE CreatedDate = LAST_YEAR

3️⃣ Accounts created this month

SELECT Id, Name, CreatedDate
FROM Account
WHERE CreatedDate = THIS_MONTH

Let me know if you need a specific query! 🚀



closedate = system.today() instead of system.today() what can we write ?

Instead of System.today(), you can use various Date functions in Apex depending on your requirement. Here are some alternatives:

1️⃣ Specific Date Functions