Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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

share|improve this question

3 Answers 3

up vote 8 down vote accepted

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.

share|improve this answer

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
share|improve this answer

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

SELECT Id FROM Opportunity WHERE CloseDate = LAST_WEEK
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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