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
rajgopal10rajgopal10 

Getting the error in SOQL query in where condition during checking the date field


I have below two fields are here, RenewalDate__c and Today

I want to checking below code in my where condition, but here i am getting error like unexpected token: '-'
RenewalDate__c- Today <= 31

how i can check this condion ?
venkat-Dvenkat-D
You cant do that directly in SOQL. You can create a formula field that calculates difference and then query that formula field
ShivaKrishna(Freelancer)ShivaKrishna(Freelancer)
Hi There,

you can not perform expressions in a query where clause. use literal in the query as below

SELECT Id FROM Opportunity WHERE RenewalDate__c > NEXT_N_DAYS:31

It will work for you.

let me know, if it helps you or need any help :)

shiva.sfdc.backup@gmail.com
 
Mahesh DMahesh D
Hi Raj,

Please tell us the actual requirement here so that it will be easy to provide the solution.

Regards,
Mahesh
rajgopal10rajgopal10
Hi Mahesh,

I have query as below:

 Map<Id,Opportunity> oppMapExt = new Map<Id,Opportunity>([select id,name,Opportunity_Name_Encrypted__c,accountid,account.name,StageName,ProductClass__c from opportunity where accountid IN: accIds AND ProductClass__c IN: lobset AND StageName <>'Closed Won' and StageName <>'Closed Lost' and Quotation__c=null]);
  

But here i want give 
below condition in where condition
and (RenewalDate__c- Today <= 31 or Today - RenewalDate__c<= 31)

 
Mahesh DMahesh D

Hi Raj,

Please look into the below code:
Map<Id,Opportunity> oppMapExt = new Map<Id,Opportunity>([select id,name,Opportunity_Name_Encrypted__c,accountid,account.name,StageName,ProductClass__c from opportunity where accountid IN: accIds AND ProductClass__c IN: lobset AND StageName <>'Closed Won' and StageName <>'Closed Lost' and Quotation__c=null
 AND (RenewalDate__c = LAST_N_DAYS: 31 OR RenewalDate__c = NEXT_N_DAYS: 31)]);

Please do let me know if it helps you.

Regards,
Mahesh
rajgopal10rajgopal10
Thank you so much Mahesh, it has worked perfectly :)