3

Since SF update to Summer 18, we are facing this issue where an Inner Class could not be set as an Aura Attribute type.

Lightning Component

<aura:component implements="force:lightningQuickActionWithoutHeader,force:hasRecordId" access="global" 
            controller="RegistrationController">
<aura:attribute name="rescheduleWrap" type="RegistrationController.RescheduleWrapper"/>
<aura:attribute name="recordId" type="Id"/> 

<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>

Apex Controller

public without sharing class RegistrationController{

 public class RescheduleWrapper{
   @AuraEnabled  
   public List<Event__c> eventList;

   @AuraEnabled  
   public boolean penalty;  

    public RescheduleWrapper(){
      this.eventList = new List<Event__c>();
      this.penalty = false; 
    }
 }
}         

Lightning Component Error

Failed to save Reschedule_Registration.cmp: Invalid <aura:attribute> type: RescheduleWrapper: Source

Please refer to this link which has the same issue. https://success.salesforce.com/issues_view?id=a1p3A0000001CBeQAM

But in our Org. we have not set any Namespace still we are facing this issue. Anyways the workaround mentioned in the above link does work for us (in which we have to create an Interface at the Top level and then make the inner Classes implement them).

Please suggest if there is any other workaround? Is this happening since Summer 18? Can we resolve it by deactivating any critical update.

1

Just for benefit of everyone we created a salesforce support ticket and below is their response:

As we discussed, I did reproduce the issue in my personal Spring 18 dev org. I also saw in my Winter 18 dev org that for components with API version 41.0, this does work.

I went over the investigation I found and it looks like, unfortunately, it was never supposed to be allowed to use Apex Inner Classes in Lightning Components. I apologize as the only place this was listed was in the following Trailhead under the Inner Classes section:

A document change has been scheduled to reflect this on our other documents. Something you could try to see if it works for you is to remove the inner class from the Top-Level class and make it into its own Top-Level Class. I tested this in my Spring 18 dev org:

Move the innerclass:

public class MyClass {
    public class MyInnerClass { 
        @AuraEnabled
        public String myProp { get; set; }
    }

}

To it's own class.

public class MyInnerClass {
@AuraEnabled
    public String myProp { get; set; }
}

In the lightning component, you can reference the MyInnerClass class as the type for the aura:attribute.

3

Sounds like namespace or no namespace is not of significance...

A simple workaround I used last year is to change:

<aura:attribute name="rescheduleWrap" type="RegistrationController.RescheduleWrapper"/>

to:

<aura:attribute name="rescheduleWrap" type="Object"/>

This avoids having to refactor the Apex code: inner classes can be very helpful in keeping simple data access object definitions next to the code that uses them (and out of the top level namespace).

JavaScript doesn't have a strong type system the type information does not appear to be used at present. I haven't found anything prescriptive in the current documentation. Perhaps sometime in the future the type will be significant, but by then there will be many Lightning Components with various values set so compatibility requirements are likely to make definitive type values optional not mandatory.

  • This worked for me - had the exact same issue as OP, summer 18 was enabled and a controller's inner class was being used as an attribute. Thanks! – Brian Mansfield Jan 9 '18 at 17:49
  • Spring 18, not summer - wishful thinking! – Brian Mansfield Jan 9 '18 at 18:06
  • @BrianMansfield So the inner class will work in Spring '18? Good to know and maybe worth posting as an answer here... – Keith C Jan 9 '18 at 18:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.