1

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

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

2 Answers 2

5

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

LAST_N_DAYS:n

With this you can achieve your requirement.

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

MyDateField >= LAST_N_DAYS:7

2
  • 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
    Commented Jul 26, 2017 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
    Commented Jul 26, 2017 at 14:24
1

instead of Date.today() - 7

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .