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?
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
=
operator. Depends on what you're going for.
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.
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