I am trying to query all the opportunities which are having a date field xyz which stores the current date + 1 week in current quarter. But my issue is I am not able to reduce (-7) days in SOQL query dynamically. Can someone suggest me. I don't want to add for loop and map to increase processing time.

I am trying something like this

select Id, abc__c from opportunity where xyz.addDays(-7)=THIS_QUARTER 
  • 1
    Custom formula, which is equal to xyz - 7 days, and filter on that field?
    – kurunve
    Commented Mar 28, 2018 at 6:46

1 Answer 1


You cannot add function on the field. If you don't want to process the logic outside the quary, you can create the relevant dates before and use them in query.

Date relevantStartDate = [calculate This Quarter Start Date] + 7;
Date relevantEndDate = [calculate This Quarter End Date] + 7;
list<opportunity> opplist = [select Id, abc__c from opportunity where xyz >  relevantStartDate :and xyz < :relevantEndDate];
  • Thanks for the reply Lorin, but I don't want to change the current quarter. I need to reduce the date field value as 7 days. And don't want to change the existing logic which populate this field value as Today()+addDays(7)
    – Sharma_raj
    Commented Mar 28, 2018 at 6:22
  • Not clear. You already update the value in this field with addDate(7)? If yes first complete the update, then run the query. Anyway, you cannot use addDays(7) inside query as you wrote. You can create formula on in field that will hold the value xyz.addDays(7) and use the formula field inside the query
    – Liron C
    Commented Mar 28, 2018 at 8:15

You must log in to answer this question.

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