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_YEARAny ideas anyone?
2 réponses
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];