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
Aleksandar AleksandarAleksandar Aleksandar 

Accessing Apex properties in Lightning Components

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.


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

        public empAvailableInnerclass() {

    public static empAvailableInnerclass getEmployeesDailyStatus(){
        return innerCList;

JavaScript controller:
getFixedTable : function(cmp, event, helper) {
        var table = cmp.get("c.getEmployeesDailyStatus");
            var state = response.getState();
            if (state === "SUCCESS") {
            } else if (state === "ERROR") {
                alert('Error : ' + JSON.stringify(errors));

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

<table id="fixedTab">
                    <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>
sachin kadian 5sachin kadian 5
are you declaring your variables static while using without inner class?
Aleksandar AleksandarAleksandar Aleksandar
Yes but it still does not show anything
I may be wrong, but I think using apex controller variable is against core design rules of Lightning. I believe lightning framework is supposed to maintain state on client side instead of on server. The server side should be used only for CRUD operations and business logic.

May be what you can try is, create a new method in apex controller that returns instance of a wrapper apex class which ecompases all the data you need in individual variables.
Aleksandar AleksandarAleksandar Aleksandar
I believe this is what I am already doing or I don't know the difference between a wrapper class and an inner class. But what I was wondering is how to access the Apex properties or variables without the need of an inner/wrapper classes. I thought there must be a way but I was not able to find any so far. I need to know it because I am migrating Visualforce pages to Lightning Components. The Visualforce pages use properties to access the data so if there is a way to keep the logic and just add @AuraEnabled would save me time.
Akhil KulkarniAkhil Kulkarni
check it for access apex class property in salesforce lightning component
Prasad N RPrasad N R
@{!Piyush_soni__c} Blantant self promotion. Coding conventions have not been followed. Explanations are not there. It works for copy paste. But, it is not easy for learners. Not sure why getters, setters, aura iterators etc. are in one page. If I were to have known this, I would have written codes to pass simple text from component to apex controller and vice versa.
Prasad N RPrasad N R and turned out to be really helpful to me! :)