1

I'm trying to build a dynamic soql where a date field has to be in the next 90 days so the soql i wrote is as below , however this isn't working:

SELECT Id FROM X__c WHERE Start_Date__c = NEXT_90_DAYS.

Any help as to where I'm doing wrong?

3 Answers 3

6

It's because you're querying the objects with a date equals to the next 90 days.

Try this:

SELECT Id FROM X__c WHERE Start_Date__c <= NEXT_90_DAYS AND Start_Date__c > TODAY
3
  • You also need Start_Date__c > TODAY, no?
    – Adrian Larson
    Commented Mar 9, 2017 at 16:18
  • @AdrianLarson You're right ! Commented Mar 9, 2017 at 16:25
  • 1
    Or alternatively, you could just use the = operator. Depends on what you're going for.
    – Adrian Larson
    Commented Mar 9, 2017 at 16:30
5

I think you're getting a but confused with LAST_N_DAYS:90 where SELECT Id FROM Account WHERE CreatedDate = LAST_N_DAYS:365 would be valid.

But, in addition to Martin Lezer's answer, you can also use:

NEXT_N_DAYS:90

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

For instance:

SELECT Id FROM Opportunity WHERE CloseDate > NEXT_N_DAYS:15

You can check out the docs here.

0

The field I'm concerned with is a Date field and not a Date time and that's the problem because checking against NEXT_90_DAYS is not right since date literals like these deals with date time both. This is how i solved this:

Date next90Days = Date.today().addDays(90);
SELECT Id FROM X__c WHERE Start_Date__c <=: next90Days
1
  • 1
    Date literals in soql work for date time as well.
    – Raul
    Commented Mar 9, 2017 at 13:42

You must log in to answer this question.

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