I want to get records last modified date is > 7.

like if(audList.LastModifiedDate > (Date.today() - 7)){ Can we do this with date literal?


If your question is related to SOQL queries, its possible. There is a query literal


With this you can achieve your requirement.

For example, if your date field is MyDateField, your query condition becomes

MyDateField >= LAST_N_DAYS:7

  • 1
    A list of all date literals that you can use is covered in the documentation page SOQL date formats and literals. There are a few 'extra' date literals that can be used as well, like N_DAYS_AGO:x. All of the 'relative date values' listed in Relative Date Values for Filter Criteria should work just fine in SOQL as well. – Derek F Jul 26 '17 at 13:05
  • 1
    @user41206 If this answer addressed your problem, please consider accepting it by clicking on the check mark/tick to the left of the answer, turning it green. This marks the question as resolved to your satisfaction, and awards reputation both to you and the person who answered. If you have >= 15 reputation points, you may also upvote the answer if you wish. There is no obligation to do either. – Adrian Larson Jul 26 '17 at 14:24

instead of Date.today() - 7

Use date.today().addDays(-7)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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