function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
krishna1krishna1 

How to get current week records in apex

Hi All,

 

How to get current week records using soql query, I want to display this week records Sunday to Saturday created records. Help me please.

 

Thanks

Gopi

 

 

Best Answer chosen by Admin (Salesforce Developers) 
kiranmutturukiranmutturu

you can write soql like this

SELECT Id FROM Account WHERE CreatedDate < THIS_WEEK

see the below url for the reference
http://www.salesforce.com/us/developer/docs/officetoolkit/Content/sforce_api_calls_soql_select_dateformats.htm

All Answers

kiranmutturukiranmutturu

you can write soql like this

SELECT Id FROM Account WHERE CreatedDate < THIS_WEEK

see the below url for the reference
http://www.salesforce.com/us/developer/docs/officetoolkit/Content/sforce_api_calls_soql_select_dateformats.htm

This was selected as the best answer
Hengky IlawanHengky Ilawan
Hi Kiran,

Shouldn't it be "WHERE CreatedDate = THIS_WEEK"?

-Hengky-
kiranmutturukiranmutturu
you can... but that was the example I gave....
Discuss with meDiscuss with me

Yes You Can use That as

 

SELECT Id FROM Account WHERE CreatedDate < THIS_WEEK

 

THIS_WEEK:

Starts 12:00:00 on the most recent first day of the week

before the current day and continues for seven full days.

First day of the week is determined by your locale

 

Sudheer R 20Sudheer R 20
Hi Krishna,

If you want to know Records crated in last 7 Days, can just go with
SELECT Id, CreatedDate  FROM Account WHERE CreatedDate = LAST_N_DAYS:7

Or if you want to know the records created from the first day of this week, then just go with
SELECT Id, CreatedDate  FROM Account WHERE CreatedDate = THIS_WEEK

see the below link for reference
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_dateformats.htm

- Sudheer Ravada-