1

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)

4
  • Are you interested in the day seven days ago, or the last seven days?
    – sfdcfox
    Jun 27, 2019 at 2:11
  • day seven days ago
    – Marc
    Jun 27, 2019 at 2:15
  • Apex code or an API call? Sorry, I should have asked that, too.
    – sfdcfox
    Jun 27, 2019 at 2:19
  • I am bulding the query in workbench/Query Editor. I cannot use apex
    – Marc
    Jun 27, 2019 at 2:21

1 Answer 1

5

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
5
  • It works, Thanks
    – Marc
    Jun 27, 2019 at 2:45
  • 1
    FYI you can just filter N_DAYS_AGO:7.
    – Adrian Larson
    Jun 27, 2019 at 3:01
  • @AdrianLarson It's not in the docs, so I didn't know about it. Guess we need a doc bug?
    – sfdcfox
    Jun 27, 2019 at 3:08
  • @AdrianLarson That link now goes to the same docs that do not have the N_DAYS_AGO filter 😢.
    – sfdcfox
    Jun 27, 2019 at 3:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .