Search code examples
classcontrollersalesforcevisualforce

Unknown property 'Integer.count_u18' visual force


I searched a lot with google, but I didn't found a solution for my error.

I get the error Unknown property 'Integer.count_u18'.

I hope you can help me.

Thanks, peX

Visual Force Page

<apex:page standardController="Account" extensions="Gruppenvertrag_c9">

<apex:form >

<apex:pageBlock Title="Long ID lautet">
    <apex:outputText value="{!Account.ID}"/>
</apex:pageBlock>

   <apex:pageBlock title="Count of Ages">
      <apex:pageBlockTable value="{!Einzelrisiko}" var="EZR">
         <apex:column value="{!EZR.Count_u18}"/>
         <apex:column value="{!EZR.Count_1822}"/>
         <apex:column value="{!EZR.Count_2227}"/>
         <apex:column value="{!EZR.Count_2732}"/>
         <apex:column value="{!EZR.Count_3237}"/>
         <apex:column value="{!EZR.Count_3742}"/>
         <apex:column value="{!EZR.Count_4247}"/>
         <apex:column value="{!EZR.Count_4752}"/>
         <apex:column value="{!EZR.Count_5257}"/>
         <apex:column value="{!EZR.Count_g57}"/>
      </apex:pageBlockTable>
   </apex:pageBlock>

</apex:form>

</apex:page>

CLASS

public class Gruppenvertrag_c9 {

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

  public Integer getEinzelrisiko() {

      //List<Einzelrisiko__c> listEZR = [SELECT COUNT() FROM Einzelrisiko__c WHERE Abgangsdatum__c = Null AND Unternehmens_Id_Long__c = :accId];
      List<Einzelrisiko__c> listEZR = [SELECT Alter__c FROM Einzelrisiko__c WHERE Abgangsdatum__c = Null AND Unternehmens_Id_Long__c = :accId];

      Integer Count_u18 = 0;
      Integer Count_1822 = 0;
      Integer Count_2227 = 0;
      Integer Count_2732 = 0;
      Integer Count_3237 = 0;
      Integer Count_3742 = 0;
      Integer Count_4247 = 0;
      Integer Count_4752 = 0;
      Integer Count_5257 = 0;
      Integer Count_g57 = 0;

      FOR(Einzelrisiko__c ein : listEZR) {
          IF(ein.Alter__c < 18) { Count_u18++; }
          IF(ein.Alter__c >18 && ein.Alter__c <=22) { Count_1822++; }
          IF(ein.Alter__c >22 && ein.Alter__c <=27) { Count_2227++; }
          IF(ein.Alter__c >27 && ein.Alter__c <=32) { Count_2732++; }
          IF(ein.Alter__c >32 && ein.Alter__c <=37) { Count_3237++; }
          IF(ein.Alter__c >37 && ein.Alter__c <=42) { Count_3742++; }
          IF(ein.Alter__c >42 && ein.Alter__c <=47) { Count_4247++; }
          IF(ein.Alter__c >47 && ein.Alter__c <=52) { Count_4752++; }
          IF(ein.Alter__c >52 && ein.Alter__c <=57) { Count_5257++; }
          IF(ein.Alter__c >57) { Count_g57++; }
      }

      return Count_u18;
      return Count_1822;
      return Count_2227;
      return Count_2732;
      return Count_3237;
      return Count_3742;
      return Count_4247;
      return Count_4752;
      return Count_5257;
      return Count_g57;

  }   

}


Solution

  • The Problem with your getEinzelrisiko() method.This method is returning Integer and the PageblockTable value attribute should be of type List.

    I have changed the Visualforce Page and Apex Class please check this.

    Visualforce :

    <apex:page standardController="Account" extensions="Gruppenvertrag_c9">
     <apex:form >
       <apex:pageBlock Title="Long ID lautet">
          <apex:outputText value="{!Account.ID}"/>
       </apex:pageBlock>
       <apex:pageBlock title="Count of Ages">
         <apex:pageBlockTable value="{!CountList}" var="EZR">`//Changed Value Attribute.`
           <apex:column value="{!EZR.Count_u18}"/>
           <apex:column value="{!EZR.Count_1822}"/>
           <apex:column value="{!EZR.Count_2227}"/>
           <apex:column value="{!EZR.Count_2732}"/>
           <apex:column value="{!EZR.Count_3237}"/>
           <apex:column value="{!EZR.Count_3742}"/>
           <apex:column value="{!EZR.Count_4247}"/>
           <apex:column value="{!EZR.Count_4752}"/>
           <apex:column value="{!EZR.Count_5257}"/>
           <apex:column value="{!EZR.Count_g57}"/>
        </apex:pageBlockTable>
      </apex:pageBlock>
     </apex:form>
    </apex:page>
    

    Apex :

    public class Gruppenvertrag_c9 {
     private Id accId {get; set;}
     public List<CountClass> CountList {get;set;} //this list contains all the values and binded to Pageblocktable
    
     public Gruppenvertrag_c9(ApexPages.StandardController stdcontroller) {
       accId = stdcontroller.getRecord().Id;
       getEinzelrisiko();//called in the constructor.
     }
    
     public void getEinzelrisiko() {
     //List<Einzelrisiko__c> listEZR = [SELECT COUNT() FROM Einzelrisiko__c WHERE Abgangsdatum__c = Null AND Unternehmens_Id_Long__c = :accId];
     List<Einzelrisiko__c> listEZR = [SELECT Alter__c FROM Einzelrisiko__c WHERE Abgangsdatum__c = Null AND Unternehmens_Id_Long__c = :accId];
    
     CountList = new List<CountClass>();
    
     FOR(Einzelrisiko__c ein : listEZR) {
    
          CountClass cc = new CountClass();
    
          IF(ein.Alter__c < 18) { cc.Count_u18++; }
          IF(ein.Alter__c >18 && ein.Alter__c <=22) { cc.Count_1822++; }
          IF(ein.Alter__c >22 && ein.Alter__c <=27) { cc.Count_2227++; }
          IF(ein.Alter__c >27 && ein.Alter__c <=32) { cc.Count_2732++; }
          IF(ein.Alter__c >32 && ein.Alter__c <=37) { cc.Count_3237++; }
          IF(ein.Alter__c >37 && ein.Alter__c <=42) { cc.Count_3742++; }
          IF(ein.Alter__c >42 && ein.Alter__c <=47) { cc.Count_4247++; }
          IF(ein.Alter__c >47 && ein.Alter__c <=52) { cc.Count_4752++; }
          IF(ein.Alter__c >52 && ein.Alter__c <=57) { cc.Count_5257++; }
          IF(ein.Alter__c >57) { cc.Count_g57++; }
    
          CountList.add(cc);//adding each record to the list
       }
      }      
      public class CountClass
      {
        public  Integer Count_u18 {get;set;}
        public  Integer Count_1822 {get;set;}
        public  Integer Count_2227 {get;set;}
        public  Integer Count_2732 {get;set;}
        public  Integer Count_3237 {get;set;}
        public  Integer Count_3742 {get;set;}
        public  Integer Count_4247 {get;set;}
        public  Integer Count_4752 {get;set;}
        public  Integer Count_5257 {get;set;}
        public  Integer Count_g57 {get;set;}
    
         public CountClass()
         {
           Count_u18 = 0;
           Count_1822 = 0;
           Count_2227 = 0;
           Count_2732 = 0;
           Count_3237 = 0;
           Count_3742 = 0;
           Count_4247 = 0;
           Count_4752 = 0;
           Count_5257 = 0;
           Count_g57 = 0;
         }
      }     
    }
    

    Hope it helps you