You need to sign in to do that
Don't have an account?
Error in SOQL query!!!!!!!!!
Hi,
Please help me to resolve the query error. :smileysad:
String purgeType = String.valueOf(bs.Purging_Type__c);
if(bs.Purging_Type__c == 'LAST_N_DAYS') {
Integer nDays = Integer.valueOf(bs.Last_n_days__c);
}
if (purgeType == 'LAST_N_DAYS') {
List<ConnectCompiere_Log__c> lastNDays = new List<ConnectCompiere_Log__c>([SELECT Id FROM ConnectCompiere_Log__c WHERE CreatedDate = LAST_N_DAYS : nDays]);
for(ConnectCompiere_Log__c rec:lastNDays) {
delete rec;
}
I am getting Error: Compile Error: expecting a number, found 'nDays' at above marked line.
How i can use custom varaiable(like nDays) instaed of using some number in place of nDays. Values for nDay, I will be getting from front end as Integer values.
Please help me.
Thnks in advance.
Actually, this is an interesting problem...
The regular SOQL syntax would be something like,
LAST_N_DAYS : n
Where n would be a number.
I've tried this in APEX, and one would think that the syntax would be LAST_N_DAYS : :nDays
However, compiling this will produce an error, because it's expecting a number.
I would also like to know the solution on how to overcome this SOQL syntax error.
The above suggestion should work though, where you say CreatedDate > :System.now().addDays( -nDays )
All Answers
Hi,
Couldn't you do something like the following
[SELECT Id FROM ConnectCompiere_Log__c WHERE CreatedDate >: System.Date().addDays(-nDays)]
Cheers,
Scott
Actually, this is an interesting problem...
The regular SOQL syntax would be something like,
LAST_N_DAYS : n
Where n would be a number.
I've tried this in APEX, and one would think that the syntax would be LAST_N_DAYS : :nDays
However, compiling this will produce an error, because it's expecting a number.
I would also like to know the solution on how to overcome this SOQL syntax error.
The above suggestion should work though, where you say CreatedDate > :System.now().addDays( -nDays )
Hello Whyser,
You did it. You are exactly correct. Great Idea....
I am very thankful to you and all.
:smileytongue: :smileytongue: