wrapper class sample

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

Lightning Component

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 🙂

(Visited 26,563 times, 1 visits today)

13 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”/>

  • I don’t want use aura:attribute type as Wrapper returns I will use a Object Type but I am getting internal Salesforce error why?

  • Hello, it is a very useful post. I did help me a lot. But how do you make the tests of the server side controller and the client side controller? Do you have an example. It would be very useful to me.

    • we don’t need to write test code for client side controller and for server side apex controller find following test class code :

      @isTest
      public class wrapperDisplayControllerTest {

      private static testmethod void testWrapper(){
      contact oContact = new contact();
      oContact.lastName = 'test';
      // add all required fields here
      insert oContact;

      test.startTest();
      wrapperDisplayController.initMethod();
      test.stopTest();
      }
      }

Leave a Reply