Skip to main content
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

 
1 risposta
  1. 28 ott 2021, 16:23
    Hi Sandy,

    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.