Apex code to show records for whole week
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
1
down vote
favorite
I want to display the record of whole week according to the day I selected.
Example: if i selected 15-08-2018 which is Wednesday, so i want the record from Monday to Sunday (13-08-2018 to 19-08-2018).
To get the weekly record of today, I had used THIS_WEEK
literal but I want to get weekly record from any date entered by user.
Please provide any suggestion either by apex or SOQL.
apex lightning-components soql
New contributor
Atul Pandey is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
1
down vote
favorite
I want to display the record of whole week according to the day I selected.
Example: if i selected 15-08-2018 which is Wednesday, so i want the record from Monday to Sunday (13-08-2018 to 19-08-2018).
To get the weekly record of today, I had used THIS_WEEK
literal but I want to get weekly record from any date entered by user.
Please provide any suggestion either by apex or SOQL.
apex lightning-components soql
New contributor
Atul Pandey is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I want to display the record of whole week according to the day I selected.
Example: if i selected 15-08-2018 which is Wednesday, so i want the record from Monday to Sunday (13-08-2018 to 19-08-2018).
To get the weekly record of today, I had used THIS_WEEK
literal but I want to get weekly record from any date entered by user.
Please provide any suggestion either by apex or SOQL.
apex lightning-components soql
New contributor
Atul Pandey is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
I want to display the record of whole week according to the day I selected.
Example: if i selected 15-08-2018 which is Wednesday, so i want the record from Monday to Sunday (13-08-2018 to 19-08-2018).
To get the weekly record of today, I had used THIS_WEEK
literal but I want to get weekly record from any date entered by user.
Please provide any suggestion either by apex or SOQL.
apex lightning-components soql
apex lightning-components soql
New contributor
Atul Pandey is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Atul Pandey is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
edited 20 mins ago


Oleksandr Berehovskiy
6,80111633
6,80111633
New contributor
Atul Pandey is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
asked 22 mins ago
Atul Pandey
82
82
New contributor
Atul Pandey is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
New contributor
Atul Pandey is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
Atul Pandey is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
Use toStartOfWeek method of Date
class. Returns the start of the week for the Date
that called the method, depending on the context user's locale. For example, the start of a week is Sunday in the United States locale, and Monday in European locales.
So you can get two dates: start of the week and end of the week (add 6 days to start of the week). Next step is to query records between calculated two dates
Date myDate = Date.today();
Date weekStart = myDate.toStartOfWeek();
Date weekEnd = weekStart.addDays(6);
List<Account> weekAccounts = [
select Id
from Account
where CreatedDate <= :weekEnd and CreatedDate >= :weekStart
];
Thank you Oleksandr Berehovskiy for your help , It's working for me.
– Atul Pandey
6 mins ago
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
Use toStartOfWeek method of Date
class. Returns the start of the week for the Date
that called the method, depending on the context user's locale. For example, the start of a week is Sunday in the United States locale, and Monday in European locales.
So you can get two dates: start of the week and end of the week (add 6 days to start of the week). Next step is to query records between calculated two dates
Date myDate = Date.today();
Date weekStart = myDate.toStartOfWeek();
Date weekEnd = weekStart.addDays(6);
List<Account> weekAccounts = [
select Id
from Account
where CreatedDate <= :weekEnd and CreatedDate >= :weekStart
];
Thank you Oleksandr Berehovskiy for your help , It's working for me.
– Atul Pandey
6 mins ago
add a comment |Â
up vote
2
down vote
accepted
Use toStartOfWeek method of Date
class. Returns the start of the week for the Date
that called the method, depending on the context user's locale. For example, the start of a week is Sunday in the United States locale, and Monday in European locales.
So you can get two dates: start of the week and end of the week (add 6 days to start of the week). Next step is to query records between calculated two dates
Date myDate = Date.today();
Date weekStart = myDate.toStartOfWeek();
Date weekEnd = weekStart.addDays(6);
List<Account> weekAccounts = [
select Id
from Account
where CreatedDate <= :weekEnd and CreatedDate >= :weekStart
];
Thank you Oleksandr Berehovskiy for your help , It's working for me.
– Atul Pandey
6 mins ago
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
Use toStartOfWeek method of Date
class. Returns the start of the week for the Date
that called the method, depending on the context user's locale. For example, the start of a week is Sunday in the United States locale, and Monday in European locales.
So you can get two dates: start of the week and end of the week (add 6 days to start of the week). Next step is to query records between calculated two dates
Date myDate = Date.today();
Date weekStart = myDate.toStartOfWeek();
Date weekEnd = weekStart.addDays(6);
List<Account> weekAccounts = [
select Id
from Account
where CreatedDate <= :weekEnd and CreatedDate >= :weekStart
];
Use toStartOfWeek method of Date
class. Returns the start of the week for the Date
that called the method, depending on the context user's locale. For example, the start of a week is Sunday in the United States locale, and Monday in European locales.
So you can get two dates: start of the week and end of the week (add 6 days to start of the week). Next step is to query records between calculated two dates
Date myDate = Date.today();
Date weekStart = myDate.toStartOfWeek();
Date weekEnd = weekStart.addDays(6);
List<Account> weekAccounts = [
select Id
from Account
where CreatedDate <= :weekEnd and CreatedDate >= :weekStart
];
edited 8 mins ago
answered 17 mins ago


Oleksandr Berehovskiy
6,80111633
6,80111633
Thank you Oleksandr Berehovskiy for your help , It's working for me.
– Atul Pandey
6 mins ago
add a comment |Â
Thank you Oleksandr Berehovskiy for your help , It's working for me.
– Atul Pandey
6 mins ago
Thank you Oleksandr Berehovskiy for your help , It's working for me.
– Atul Pandey
6 mins ago
Thank you Oleksandr Berehovskiy for your help , It's working for me.
– Atul Pandey
6 mins ago
add a comment |Â
Atul Pandey is a new contributor. Be nice, and check out our Code of Conduct.
Atul Pandey is a new contributor. Be nice, and check out our Code of Conduct.
Atul Pandey is a new contributor. Be nice, and check out our Code of Conduct.
Atul Pandey is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f235421%2fapex-code-to-show-records-for-whole-week%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password