Apex code to show records for whole week

The name of the pictureThe name of the pictureThe name of the pictureClash 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.










share|improve this question









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.

























    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.










    share|improve this question









    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.





















      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.










      share|improve this question









      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






      share|improve this question









      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.











      share|improve this question









      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.









      share|improve this question




      share|improve this question








      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.




















          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
          ];





          share|improve this answer






















          • Thank you Oleksandr Berehovskiy for your help , It's working for me.
            – Atul Pandey
            6 mins ago










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "459"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );






          Atul Pandey is a new contributor. Be nice, and check out our Code of Conduct.









           

          draft saved


          draft discarded


















          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






























          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
          ];





          share|improve this answer






















          • Thank you Oleksandr Berehovskiy for your help , It's working for me.
            – Atul Pandey
            6 mins ago














          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
          ];





          share|improve this answer






















          • Thank you Oleksandr Berehovskiy for your help , It's working for me.
            – Atul Pandey
            6 mins ago












          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
          ];





          share|improve this answer














          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
          ];






          share|improve this answer














          share|improve this answer



          share|improve this answer








          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
















          • 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










          Atul Pandey is a new contributor. Be nice, and check out our Code of Conduct.









           

          draft saved


          draft discarded


















          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.













           


          draft saved


          draft discarded














          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













































































          Comments

          Popular posts from this blog

          What does second last employer means? [closed]

          List of Gilmore Girls characters

          One-line joke