2

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

1 Answer 1

6

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