• Aleksandar Aleksandar
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 2
    Replies
Hi all,
I am trying to build lightning components and I want to access the properties of an Apex controller in the components to display certain data. When try to display the values like in Visualforce (with added @AuraEnabled), it does not work. When I place the properties inside an inner class and create a method that has a return type as that inner class, then when I return a list of that class I can see the data. Bellow is the code which displays data, but I want to use it without an inner class and extra method to get that data. If anybody can help please let me know.

Thanks!

Apex:
public with sharing class EmployeeAvailability {
public static empAvailableInnerclass innerCList;
 
public class empAvailableInnerClass {
        @AuraEnabled
        public Decimal aetPerc {get;set;}
        @AuraEnabled
        public Integer totalEmployeesToday {get;set;}
        @AuraEnabled
        public Decimal budgetThisMonth {get;set;}
        @AuraEnabled
        public Decimal averageMargin {get;set;}
        @AuraEnabled
        public Object averageRate {get;set;}
        @AuraEnabled
        public Integer illnessToday {get;set;}
        @AuraEnabled
        public List<availableNextSixty> AvailableSixty{get;set;}
        @AuraEnabled
        public Date DateAfterTwoMonths {get;set;}

        public empAvailableInnerclass() {
            DateAfterTwoMonths=Date.today().addmonths(2);
        }
   }

@AuraEnabled
    public static empAvailableInnerclass getEmployeesDailyStatus(){
        runRetrieve();
        return innerCList;
    }
}

JavaScript controller:
getFixedTable : function(cmp, event, helper) {
        //debugger;
        var table = cmp.get("c.getEmployeesDailyStatus");
        table.setCallback(this,function(response){
            var state = response.getState();
            if (state === "SUCCESS") {
                cmp.set("v.tabTable",response.getReturnValue());
            } else if (state === "ERROR") {
                alert('Error : ' + JSON.stringify(errors));
            }
        });
        $A.enqueueAction(table);
    }


Lightning Component:
<aura:handler name="init" value="{!this}" action="{!c.getFixedTable}"/>
<aura:attribute name="tabTable" type="EmployeeAvailabilityLightning"/>

<table id="fixedTab">
            <thead>
                <tr>
                    <th>Total employees today : {!v.tabTable.totalEmployeesToday}</th>
                    <th>Budget this month : {!v.tabTable.budgetThisMonth}</th>
                    <th>Average Margin : {!v.tabTable.averageMargin} %</th>
                    <th>Available next 60 days : {!v.tabTable.AvailableSixty.size}</th>
                    <th>Employee hours available today : {!v.tabTable.aetPerc} %</th>
                    <th>Illness Today: {!v.tabTable.illnessToday}</th>
                </tr>
            </thead>
        </table>
Hi all,
I am trying to build lightning components and I want to access the properties of an Apex controller in the components to display certain data. When try to display the values like in Visualforce (with added @AuraEnabled), it does not work. When I place the properties inside an inner class and create a method that has a return type as that inner class, then when I return a list of that class I can see the data. Bellow is the code which displays data, but I want to use it without an inner class and extra method to get that data. If anybody can help please let me know.

Thanks!

Apex:
public with sharing class EmployeeAvailability {
public static empAvailableInnerclass innerCList;
 
public class empAvailableInnerClass {
        @AuraEnabled
        public Decimal aetPerc {get;set;}
        @AuraEnabled
        public Integer totalEmployeesToday {get;set;}
        @AuraEnabled
        public Decimal budgetThisMonth {get;set;}
        @AuraEnabled
        public Decimal averageMargin {get;set;}
        @AuraEnabled
        public Object averageRate {get;set;}
        @AuraEnabled
        public Integer illnessToday {get;set;}
        @AuraEnabled
        public List<availableNextSixty> AvailableSixty{get;set;}
        @AuraEnabled
        public Date DateAfterTwoMonths {get;set;}

        public empAvailableInnerclass() {
            DateAfterTwoMonths=Date.today().addmonths(2);
        }
   }

@AuraEnabled
    public static empAvailableInnerclass getEmployeesDailyStatus(){
        runRetrieve();
        return innerCList;
    }
}

JavaScript controller:
getFixedTable : function(cmp, event, helper) {
        //debugger;
        var table = cmp.get("c.getEmployeesDailyStatus");
        table.setCallback(this,function(response){
            var state = response.getState();
            if (state === "SUCCESS") {
                cmp.set("v.tabTable",response.getReturnValue());
            } else if (state === "ERROR") {
                alert('Error : ' + JSON.stringify(errors));
            }
        });
        $A.enqueueAction(table);
    }


Lightning Component:
<aura:handler name="init" value="{!this}" action="{!c.getFixedTable}"/>
<aura:attribute name="tabTable" type="EmployeeAvailabilityLightning"/>

<table id="fixedTab">
            <thead>
                <tr>
                    <th>Total employees today : {!v.tabTable.totalEmployeesToday}</th>
                    <th>Budget this month : {!v.tabTable.budgetThisMonth}</th>
                    <th>Average Margin : {!v.tabTable.averageMargin} %</th>
                    <th>Available next 60 days : {!v.tabTable.AvailableSixty.size}</th>
                    <th>Employee hours available today : {!v.tabTable.aetPerc} %</th>
                    <th>Illness Today: {!v.tabTable.illnessToday}</th>
                </tr>
            </thead>
        </table>