I need to check if close date of opportunity is equal to current fiscal year in apex.Can someone explain me how to use get current fiscal year.FYI my Org doesn't have custom Fiscal year setup.(Its Standard Fiscal year).


You can get the month of your organisation fiscal year with this query :

Integer orgFiscalMonth = [SELECT FiscalYearStartMonth FROM Organization].FiscalYearStartMonth;

And create a Date variable using this :

Date orgFiscalYear = Date.newinstance(system.today().year(), orgFiscalMonth, 1);
| improve this answer | |

I like this approach better, because it will work in whichever fiscal year setup you're in. It makes use of an SFDC table that is not very well known:

String currentFiscalYear = [SELECT FiscalYearSettings.Name FROM Period WHERE Type = 'Year' AND StartDate <= TODAY AND EndDate >= TODAY].FiscalYearSettings.Name;
| improve this answer | |
  • The cool thing about this query is you can easily determine which fiscal period you're in as well, and the year of the fiscal period: Select Type, StartDate, EndDate, Number, FiscalYearSettings.PeriodId, From Period Where Type='Quarter' and startDate <= TODAY and endDate >= TODAY – DaveS Oct 29 '15 at 8:49
  • 1
    I also prefer this method for the OP's use case, but it's risky for determining fiscal quarters/years of a generic date. The Period object is populated automagically by SF via what seems to be an internal, system-wide trigger on all objects. Anytime a record is created (excluding those made in unit tests) containing a date field with a value set to a year not represented by any Period records then new, corresponding Period records are generated. Thus, if the filter in the SOQL query above were tied to a generic date with a year not represented by any Period records you could have problems. – Scott Covert Jul 29 '16 at 20:36
  • How do you substitute Today with a date if one is looking for future Fiscal year, unless one formats the date [YYYY,MM,DD]. Any ideas? – mubs Sep 9 '19 at 23:11
  • Hi Mubeen. Probably better chance of success if you ask a new question on salesforce stackexchange for this. That way we can get the question clear and have more people look at it. – Guy Clairbois Sep 10 '19 at 9:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.