function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
rohit.mehtarohit.mehta 

NEXT_N_DAYS Query

I have a query where I want to use the NEXT_N_DAYS in my query but the problem is that the number of days is a variable in my code.
 
When I try writing as
 
Code:
Integer mydays = 20;
Select Id from Opportunity where CloseDate = NEXT_N_DAYS:mydays 

 
I get an error "Expecting a number, found mydays". I have tried the following variations but none of them work -
 
Code:
NEXT_N_DAYS::mydays 
NEXT_N_DAYS:mydays 
NEXT_N_DAYS: =:mydays 

How do I do this?

Thanks,
Rohit
mikefmikef
rohit:

I don't have time to test this but try changing the variable in your code to a string.

Code:
String mydays = '20';
Select Id from Opportunity where CloseDate = NEXT_N_DAYS:mydays 

 Sorry I don't have time to test this.

rohit.mehtarohit.mehta
No Luck..same issue
 
Error -
expecting a number, found 'mydays' 
 
The issue is that both the apex variable and the NEXT_N_DAYS query needs the colon ":".
 
Thanks
Rohit