0

I need to use multi APEX controller in lightning component.

I thought I can use Controller Extension like visualforce page, but I couldn't.

I got error like Invalid attribute "extensions".

It isn't usable in Aura, or there are some solutions?

Developer Guide for Controller Extension in visualforce https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_extension.htm

2 Answers 2

3

You can't use multiple Apex-Controller in Lightning Components. But you can use your main controller as a start point to call functions from other Apex-controllers:

LC:

<aura:component controller="MainController">
.
.
</aura:component>

Apex:

public class MainController{

    public MainController() {

    }

    @AuraEnabled
    public static String callFun2FromSubApexClass() {
         SubClass.fun2();
    }
}

And call the callFun2FromSubApexClass() from your the javascript controller

2

You cannot use multiple apex controllers in AURA (but you can in LWC). If you need to refer to refer methods from multiple classes, you can return them from base controller:

@AuraEnabled
public static List<String> myMethod1() {
    return SomeOtherClass1.myMethod1();
}

@AuraEnabled
public static List<String> myMethod2() {
    return SomeOtherClass2.myMethod2();
} 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .