[SalesForce] Unable to save Lightning Component because of Save error for Custom Apex Class type attribute

I'm trying to create a Lightning Component and there is a Custom Apex Controller class with a child class in it.

But I'm receiving an error like this:

Failed to save undefined: No TYPE named apex://MyAccountController.wChildItem[] found : [markup://vctm:AccCtrl]: Source

The code for my Lightning Component looks like this:

Code for .cmp file:

<aura:component controller="MyAccountController">
    <!-- Attributes -->
    <aura:attribute name="children" type="MyAccountController.wChildItem[]" />
...
...
</aura:component>

Code for APEX Class:

public with sharing class MyAccountController {

    @AuraEnabled
    public  static  wChildItem[]    findRecords() {
        List<wChildItem> items  = new List<wChildItem>();
    ...
        ...
        return items;
    }

    public class wChildItem {
        @AuraEnabled
        public  string  sname   { get;set; }

        @AuraEnabled
        public  string  stype   { get;set; }

        public wChildItem(string n, string t) {
            sname   = n;
            stype       = t;
        }
    }
}

Why do I keep getting the no TYPE cannot be found error on save? What is a workaround for this error?

Best Answer

Visualforce Components have a problem where they can't have attributes that reference an inner class as their type. You might be seeing something similar with your Lightning Component.

See this question: Reference inner class in Visualforce component

Try breaking wChildItem out into its own class.

You also may need to use your namespace when referencing your inner class, if you didn't pick a namespace, your namespace is likely "c".

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/ref_attr_types_apex.htm

<aura:attribute name="children" type="c.wChildItem[]" />

Related Topic