Find your content:

Search form

You are here

Current Fiscal Year in apex

 
Share

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).


Attribution to: sfdc

Possible Suggestion/Solution #1

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;

Attribution to: Guy Clairbois

Possible Suggestion/Solution #2

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);

Attribution to: melmoussaoui
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/33627

My Block Status

My Block Content