Find your content:

Search form

You are here

Finding opportunities closed in last week

 
Share

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


Attribution to: dublintech

Possible Suggestion/Solution #1

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

Attribution to: Sergej Utko

Possible Suggestion/Solution #2

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

SELECT Id FROM Opportunity WHERE CloseDate = LAST_WEEK

Attribution to: Daniel Hoechst

Possible Suggestion/Solution #3

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.


Attribution to: zjeh
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/5226

My Block Status

My Block Content