You need to sign in to do that
Don't have an account?
![sandy hello sandy hello](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
How to get current fiscal year start date and end date using apex
I have requirement to fetch records for current fiscal year through soql in apex.
currentFiscalYear = [SELECT FiscalYearSettings.Name,StartDate,EndDate FROM Period WHERE Type = 'Year' AND StartDate <= TODAY AND EndDate >= TODAY].FiscalYearSettings.Name;
I am using soql select id,name from Service where CreatedDate >= currentFiscalYear.StartDate and CreatedDate <= currentFiscalYear.EndDate which is giving error System.QueryException: Variable does not exist: currentFiscalYear.StartDate
currentFiscalYear = [SELECT FiscalYearSettings.Name,StartDate,EndDate FROM Period WHERE Type = 'Year' AND StartDate <= TODAY AND EndDate >= TODAY].FiscalYearSettings.Name;
I am using soql select id,name from Service where CreatedDate >= currentFiscalYear.StartDate and CreatedDate <= currentFiscalYear.EndDate which is giving error System.QueryException: Variable does not exist: currentFiscalYear.StartDate
You're getting errors because you didn't define the variable currentFiscalYear above, you have directly used it.
This should be like this -
String currentFiscalYear = [SELECT FiscalYearSettings.Name FROM Period WHERE Type = 'Year' AND StartDate <= TODAY AND EndDate >= TODAY].FiscalYearSettings.Name;
Please mark it as the best answer, if it helps in any way.
Thanks.