Created
April 6, 2012 19:47
-
-
Save boxfoot/2322443 to your computer and use it in GitHub Desktop.
Determine current fiscal year in Apex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* (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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Amazing.