Skip to main content
Hieu Truong (Hylaine) a posé une question dans #Apex
Is it possible to query the year of a Holiday Record?

I created an Easter 2019 Holiday with the date of 4-21-2019

I tried the following:

Integer thisYear = date.today().year();

List<Holiday>Easter = [Select Id, ActivityDate,Name from Holiday where Name like '%Easter%' and Calendar_YEAR(ActivityDate) =:thisYear];

Received this error message: 

like '%Easter%' and Calendar_YEAR(ActivityDate) =:thisYear

                                  ^

ERROR at Row:1:Column:88

field ActivityDate does not support date function CALENDAR_YEAR

Any ideas anyone?
2 réponses
  1. 3 janv. 2019, 06:28

    You can't compare the result of a date function with a date literal in a WHERE clause.

    Integer thisYear = date.today().year();

    Date startRange = Date.newInstance(thisYear, 1, 1),

    endRange = Date.newInstance(thisYear, 12, 31);

    List<Holiday> holidays = [SELECT Id, ActivityDate,Name from Holiday WHERE Name like '%Easter%' AND ActivityDate >= :startRange AND ActivityDate <= :endRange];

     
0/9000