[SalesForce] Date – Number of days filter in SOQL

My SOQL Query is giving unknown parsing error. Whats the issue?

Select id, Account_Name__C, Account_Name__r.Email__c from QOACH_Conversion__c where LAU_CSAT_rating_of_IQOS_Coach__c= null AND CreatedDate= Date.today().addDays(-7)

Best Answer

The syntax you've quoted is only for Apex code (and needs a : prefixing it). There's also no such thing as the "between" operator in SOQL. As an alternative, you can use two date filters:

SELECT ... FROM ... WHERE ... AND CreatedDate = LAST_N_DAYS:7 AND CreatedDate != LAST_N_DAYS:6

Or, the apparently undocumented N_DAYS_AGO filter:

SELECT ... FROM ... WHERE ... AND CreatedDate = N_DAYS_AGO:7
Related Topic