Skip to content

Instantly share code, notes, and snippets.

@cdeckert
Forked from boxfoot/gist:2322443
Last active December 22, 2015 03:49
Show Gist options
  • Save cdeckert/6412770 to your computer and use it in GitHub Desktop.
Save cdeckert/6412770 to your computer and use it in GitHub Desktop.
public static Date currentFYStartDate
{
get
{
if (currentFYStartDate == null)
{
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();
}
}
currentFYStartDate = Date.newInstance(currentFY, orgInfo.FiscalYearStartMonth, 1);
}
return currentFYStartDate;
}
set;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment