How To Access Apex Class Properties In Lightning Component

Lightning Component

Hey guys, today in this post we will learn that how we can access apex class properties in lightning component.

Prerequisites : basic understanding of Lightning Component and Apex programming


  • First we create component controller class .
  • It’s have 3 {get ;set;}  property variable on line number 5,6 and 7, with @AuraEnabled annotation .
  • The @AuraEnabled annotation enables client- and server-side access to an apex controller method and controller property. Providing this annotation makes your methods and properties available to your Lightning components.
  • In this controller we have a single method which return type is class type .


    • In our test component we have a aura:attribute which type is class Type.
    • On the component initialize  call initClass() method and set return value in aura:attribute.
    • And finally access class property in component by {! v.objClassController.PropertyName }



apex class properties
Like our facebook page for new post updates.?

Other popular Post :

Follow us for new post updates. & Don’t forget to bookmark this site for your future reference.

Facebook :

Instagram :

(Visited 16,985 times, 1 visits today)


  • Hi I have a issue using apex class property in lightning component, I used this to replicate the custom javascript button in classic to lightning. please help me

  • How can this be acheived in Opposite direction? passing a value from Component to an Auraenabled method in Server and using that value for other dependent methods in same class

  • It would have been much better if minimal code were to have been put up. Maybe one to get and one to set. Also, the standard coding conventions have not been followed. If I were to have known these, maybe, I would have started with Apex class with a string and passing that to Lightning and displaying it. Not sure why aura iterators, getters, setters, and all others are in one page without much explanation. Works for copy paste. But, not easy for learners.

  • This is great, thank you for sharing. This works for me to initialize the wrapper class and preload values. What if I want to update the class property values when an event occurs after the page is initialized? Ive tried this…

    component.set(‘v.objClassController.DeveloperName’, ‘John Brown’);

    But received…

    Action failed: c:Component_Name$controller$updateName [Cannot read property ‘DeveloperName’ of null]

    Surely I don’t have to do a callback each time I want to update the values. Thoughts?

    Thanks ahead of time.


  • Great post, Piyush,

    I’ve combined your solution with those described in

    and separated the attributes collection into a wrapper class which makes a much tidier looking solution.

    I also added an update method as requested above.

    Attributes Wrapper Class:

    Demonstration bundle “HelloWorld”…



    And the Apex controller:


Leave a Reply