function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sascha DeinertSascha Deinert 

Date Calender Count

Hi,
Could you help me with the problem below. I got the error "No access to entity: Calendar in row 1, column 8", but I didn't know exactly the error.
Is the following syntax ok?
 
IF(Calendar.Year(EZR.Beginn_der_HV__c) = This.Year) { 
  Bestandsentwicklung_CY++; 
}
The field Beginn_der_HV__c includes dates. I want to count the Beginn_der_HV__c if the calendar year from this field is like current year, also I need to count the field if the calendar year from this field is like current year - 2.

Thanks for your help, Sascha
 
public class testfor6_c {

private Id accId {get; set;}
public testfor6_c(ApexPages.StandardController stdcontroller) { 
    accId = stdcontroller.getRecord().Id;

    Bestandsentwicklung_CY = 0;
    Bestandsentwicklung_CY_2 = 0;

    getEZRen();   
}

public Integer Bestandsentwicklung_CY {get; set;}
public Integer Bestandsentwicklung_CY_2 {get; set;}

public void getEZRen() {

List<Einzelrisiko__c> EZRList = [SELECT Beginn_der_HV__c FROM Einzelrisiko__c WHERE Abgangsdatum__c = Null AND Unternehmens_Id_Long__c = :accId]; 

FOR (Einzelrisiko__c EZR : EZRList) { 

    IF(Calendar.Year(EZR.Beginn_der_HV__c) = This.Year) { Bestandsentwicklung_CY++; }
    IF(Calendar.Year(EZR.Beginn_der_HV__c) = This.Year-2) { Bestandsentwicklung_CY_2++; }    

} } }



 
Best Answer chosen by Sascha Deinert
Gil GourévitchGil Gourévitch
Hi,
there is a little error here, sorry : you need to use "=="
change :
IF(EZR.Beginn_der_HV__c.year() = Date.today().year()) { Bestandsentwicklung_CY++; }
to :
IF(EZR.Beginn_der_HV__c.year() == Date.today().year()) { Bestandsentwicklung_CY++; }
Hope this helps
Gil

Question Solved ? Please mark as the best answer to help other users !

All Answers

Gil GourévitchGil Gourévitch
Hi,
If you want to get the yar part of a date or datetime field, just use :
IF(Beginn_der_HV__c.year() = This.Year) { Bestandsentwicklung_CY++; 
Hope this helps
Gil

Question Solved ? Please mark as the best answer to help other users !
Sascha DeinertSascha Deinert
Thanks for your reponse, but it doesnt work. Variable does not exist: Year
Because I need in front of the field "Beginn_der_HV__c" the listname EZR in the for loop.
IF(EZR.Beginn_der_HV__c.year() = This.Year) { Bestandsentwicklung_CY++; }
Mikola SenykMikola Senyk

Just create local variable thisYear and put it before for loop:

Integer thisYear = Date.today().year();
and change This.Year in your code to thisYear.
Gil GourévitchGil Gourévitch
Yes, you need to replace this.year by Date.today().year() in your code :
IF(EZR.Beginn_der_HV__c.year() = Date.today().year()) { Bestandsentwicklung_CY++; }
Hope this helps
Gil

Question Solved ? Please mark as the best answer to help other users !
 
Sascha DeinertSascha Deinert
Unfortunately I still get an error, same error with both proposal.

Expression cannot be assigned
Gil GourévitchGil Gourévitch
Hi,
there is a little error here, sorry : you need to use "=="
change :
IF(EZR.Beginn_der_HV__c.year() = Date.today().year()) { Bestandsentwicklung_CY++; }
to :
IF(EZR.Beginn_der_HV__c.year() == Date.today().year()) { Bestandsentwicklung_CY++; }
Hope this helps
Gil

Question Solved ? Please mark as the best answer to help other users !
This was selected as the best answer