The below query doesn't return any results

select Phone__c from Application__c where Orientation_Date__c < NEXT_N_DAYS:8 and Orientation_Date__c > NEXT_N_DAYS:1

But the next query returns 2 records with Orientation_Date__c 2017-07-27 and 2017-07-28

select Phone__c from Application__c where Orientation_Date__c > NEXT_N_DAYS:1

Today is 2017-07-25 so these 2 records should meet the criteria for the first query right? Why aren't they being returned?

  • You say that it does return records with those dates. The behavior you describe is correct. Can you clarify what you observe versus what you expect?
    – Adrian Larson
    Jul 25, 2017 at 20:56
  • I expect the top query to also return those records that the second query returns
    – gary69
    Jul 25, 2017 at 20:57

1 Answer 1


Take a look at the documentation on Date Literals

Date Literal

For the number n provided, starts 00:00:00 of the current day and continues for the next n days.

SELECT Id FROM Opportunity WHERE CloseDate > NEXT_N_DAYS:15

Since the range starts from midnight today, using < NEXT_N_DAYS:n is equivalent to < TODAY.

Unfortunately, unlike N_DAYS_AGO:n, there does not appear to be any sort of N_DAYS_FROM_NOW:n literal, so I'm not sure if there is a workaround in pure SOQL. Your best bet might be to create a formula for Days_From_Now__c and filter on that instead.

  • 1
    I love salesforce
    – gary69
    Jul 25, 2017 at 21:08

You must log in to answer this question.

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