[SalesForce] Finding opportunities closed in last week

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

Best Answer

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.

Related Topic