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
jayesh pagarejayesh pagare 

how do I get opportunity close date is two year ago in soql query?

below are two working query for getting close date on current and last fiscal year..but i want a query to get opportunity having close date two years before something like: (CloseDate = LAST_FISCAL_YEAR-1)

1]   [SELECT SUM(Amount),AccountId FROM opportunity where AccountId IN :AccountIDsAND CloseDate=LAST_FISCAL_YEAR GROUP BY AccountId]

2]   [SELECT SUM(Amount),AccountId FROM opportunity where AccountId IN :AccountIDsAND CloseDate=THIS_FISCAL_YEAR GROUP BY AccountId]
 
Best Answer chosen by jayesh pagare
Agustina GarciaAgustina Garcia
What about anything like this?
Date currentDate = System.today(); //our your fiscal year date
Date newFiscalYear = currentDate.addYears(-2);
[SELECT SUM(Amount),
        AccountId 
FROM opportunity 
WHERE AccountId IN :AccountIDs 
AND CloseDate=:newFiscalYear 
GROUP BY AccountId]
Hope this helps
Agustina
 

All Answers

buggs sfdcbuggs sfdc
HI

Check this link it may helps
 
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_dateformats.htm

 
Agustina GarciaAgustina Garcia
What about anything like this?
Date currentDate = System.today(); //our your fiscal year date
Date newFiscalYear = currentDate.addYears(-2);
[SELECT SUM(Amount),
        AccountId 
FROM opportunity 
WHERE AccountId IN :AccountIDs 
AND CloseDate=:newFiscalYear 
GROUP BY AccountId]
Hope this helps
Agustina
 
This was selected as the best answer
jayesh pagarejayesh pagare
Thanks a lot Agustina! it worked :)