Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Determine current fiscal year in Apex
/* (c) Benj Kamm 2012
* Determine current fiscal year in Apex -- add this method to a class that needs it.
*
* FiscalYearStartMonth - Integer 1-12 corresponds to starting month of FY
* UsesStartDateAsFiscalYearName - If false, FY Name is year of ending month; if true, name from beginning month.
*/
private integer getCurrentFY() {
Organization orgInfo = [SELECT FiscalYearStartMonth, UsesStartDateAsFiscalYearName
FROM Organization
WHERE id=:Userinfo.getOrganizationId()];
Date today = system.today();
Integer currentFY;
if (today.month() >= orgInfo.FiscalYearStartMonth) {
if (orgInfo.UsesStartDateAsFiscalYearName) {
currentFY = today.year();
} else {
currentFY = today.year() + 1;
}
} else {
if (orgInfo.UsesStartDateAsFiscalYearName) {
currentFY = today.year() - 1;
} else {
currentFY = today.year();
}
}
return currentFY;
}
@capeterson

This comment has been minimized.

Copy link

capeterson commented May 13, 2012

Thanks for this! Amazingly helpful.

@guyclairbois

This comment has been minimized.

Copy link

guyclairbois commented Jun 28, 2015

Here's a simpler and shorter approach:
String currentFiscalYear = [SELECT FiscalYearSettings.Name FROM Period WHERE Type = 'Year' AND StartDate <= TODAY AND EndDate >= TODAY].FiscalYearSettings.Name;

@SamCousinsGB

This comment has been minimized.

Copy link

SamCousinsGB commented Sep 27, 2018

Here's a simpler and shorter approach:
String currentFiscalYear = [SELECT FiscalYearSettings.Name FROM Period WHERE Type = 'Year' AND StartDate <= TODAY AND EndDate >= TODAY].FiscalYearSettings.Name;

Amazing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.