wrapper class sample

How to Use Wrapper Class In Lightning Component -Inner Class Example

Lightning Component

Sharing is caring!

Hi Guys, Today In this post we are going to learn about how to Use wrapper class or Inner Class in salesforce lightning component OR how to display data from wrapper class in lightning component.

In this sample example we are create a lightning component, and display standard object contact records and other data using wrapper class properties.

Using Wrapper Class In Lightning Component Example :
Lightning Component Output:wrapper class
Lightning Component Output:

Apex class Controller [Include Wrapper/Inner class].

  • To access apex[wrapper ] class properties in Lightning Component you have need to make them @AuraEnabled.
  • see code comments

Lightning Component [testWrapper.cmp]

  • see code comments

javaScript Controller [testWrapperController.js]

  • see code comments
demo.app [Lightning Application]

Lightning Component Output: wrapper class
Lightning Component Output:

Like our facebook page for new post updates. & Don’t forget to bookmark this site for your future reference.

if you have any suggestions or issue with it, you can post in comment box 🙂

Sharing is caring!

(Visited 5,051 times, 8 visits today)

6 comments

  • Hi piyush

    I am getting internal server error when I execute your code. The only change I made is I added in component  <ltng:require styles=”{!$Resource.SLDS24 + ‘/assets/styles/salesforce-lightning-design-system.css’}”/>

  • Hi piyush,

    When i am saving the component I am encountering below error:

    FIELD_INTEGRITY_ExCEPTION

    Failed to save testWrapper.cmp: Invalid <aura:attribute> type:wrapperClass: Source

    Could  you please suggest on this.

    Thanks in advance.

    Regards,

    Vardhan

  • @Vardhan

    I got same error in API Version 41.0 but not in API Version 38.0. Still I’ll find solution for this error.

  • Thank you so much for your quick response.

    I have updated the below code and it is working fine now.

    Existing code:

    <aura:attribute name=“wrapperList” type=“wrapperDisplayController.wrapperClass”/>

    Updated code:

    <aura:attribute name=”wrapperList” type=”object”/>

Leave a Reply