1

I am looking to get all opportunities closed in last week. I know System.today() is a neat way to get the current date but just wondering is there any other neat way to get all opportunities closed in last week? Or a date range which covers last week?

Thanks

9

There are Date Literals you can use in the query criteria. I am not sure if you are looking for last calendar week or last 7 days week, but you are covered either way plus several others-

[SELECT Id, Name FROM Opportunity WHERE CloseDate = LAST_WEEK]

Starts 12:00:00 on the first day of the week before the most recent first day of the week and continues for seven full days. First day of the week is determined by your locale.

or

[SELECT Id, Name FROM Opportunity WHERE CloseDate = LAST_N_DAYS:7]

For the number n provided, starts 12:00:00 of the current day and continues for the last n days.

6

Here is a cool doc about date formats in SOQL: Date Formats and Date Literals

You could use LAST_WEEK for sure.

Something like:

Select Id, Name From Opportunity Where CloseDate = LAST_WEEK
6

Using SOQL, there are a lot of date literals you can use.

SELECT Id FROM Opportunity WHERE CloseDate = LAST_WEEK

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.