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
naresh johnnaresh john 

How to get current fiscal year

HI every one,

 

   How to get current fiscal year into a variable. Is there any method to read current fiscal year. I know how to write soql queries based on fiscal year. But how to get the value of current fiscal year into a variable.

 

 

Please help me.

 

Thanks,

Naresh

Best Answer chosen by Admin (Salesforce Developers) 
SteveBowerSteveBower

Integer FiscalYearStartMonth = [select FiscalYearStartMonth from Organization where id=:Userinfo.getOrganizationId()].FiscalYearStartMonth;

 

e.g. get your organization id from Userinfo, and query th information about your organization.   Based on the current date and the FYStartmonth, you can determine what year you're in.

 

If that's not what you're looking for, I don't understand your question.  Best, Steve.

All Answers

SteveBowerSteveBower

Integer FiscalYearStartMonth = [select FiscalYearStartMonth from Organization where id=:Userinfo.getOrganizationId()].FiscalYearStartMonth;

 

e.g. get your organization id from Userinfo, and query th information about your organization.   Based on the current date and the FYStartmonth, you can determine what year you're in.

 

If that's not what you're looking for, I don't understand your question.  Best, Steve.

This was selected as the best answer
naresh johnnaresh john

HI Steve ,

 

thanks for the reply. But my requirement is,  I want to assign the current fiscal year to a variable.

Integer CurrentYear = datetime.now().year();

 with the above code I will get current year. But how to get current fiscal year. Need more clarification please let me know.

 

 

Thanks,

Naresh

 

SteveBowerSteveBower

Ok...

 

Today is Feb 8th.  

 

If your Fiscal year starts on Jan 1, what fiscal year are you now in?

 

If your Fiscal Year Start Month is February, what fiscal year are you now in?

 

If your Fiscal Year Start Month is March, what fiscal year are you now in?

 

Given todays date (from Date.today()) , and the starting month for your organizations fiscal year (from my previous code), you can figure out for yourself what fiscal year you are in and assign it to a variable.

 

Best, Steve.

naresh johnnaresh john

HI Steve,

 

    Thanks again for the reply. What if I want to make a package. Fiscal year is different for different organizations. How can I make a managed package.

 

Thanks,

Naresh B 

SteveBowerSteveBower

You're packaging up Apex code.  You put the logic in the Apex.  Where are you confused?

 

Perhaps someone else can help you better than I

 

Best, Steve.

kantravikantkantravikant

If you have one fisical year in your org.

Fiscal_Year__c year = [Select name from Fiscal_Year__c ];

 

Simillarly modify in query for having more fisical years.