I am running an SOQL query to get 10th, 30th and 60th days before created records to notify users to take action. I wrote a query using LAST_N_DAYS:10 OR LAST_N_DAYS:30 in WHERE condition, but the expected results are not coming. I will have to write my own date logic behind to get it to work but why the out of the box feature in SOQL is not returning expected records. Am I doing any mistake here?

SELECT Id, LastModifiedDate FROM Account WHERE LastModifiedDate = LAST_N_DAYS:10

In the above Query, my understanding is that we are supposed to get the records which are modified 10 days back. But the results are some random dated records. Please refer to the screenshot below. enter image description here

This is the same for CreatedDate and other dateTime datatype field in other custom object as well. Please advice. Thank you.


1 Answer 1


That's true! If you see the documentation, it clearly mentions it will have records having timestamp b/w today & N days back.

From documentation:

For the number n provided, starts with the current day and continues for the past n days. This range includes the current day, not just previous days. For example, LAST_N_DAYS:1 includes yesterday and today.

You can probably try N_DAYS_AGO

Starts 00:00:00 on the nth day before and continues for 24 hours.

or the custom date logic if you want.

  • 1
    Alternative could also be Field = LAST_N_DAYS:10 AND Field <> LAST_N_DAYS:9.
    – sfdcfox
    Apr 6, 2023 at 14:35
  • I don't understand this @sfdcfox. Will we be getting only 10 days created records if we use this query?
    – AshSFcloud
    Apr 7, 2023 at 10:33

You must log in to answer this question.

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