function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
LemmingLemming 

Unable to resolve "Unable to find action 'getBoatTypes' on the controller of c:BoatSearchForm Failing descriptor: {c:BoatSearchForm}"

Hi,

I've been learning Lightning Components on Trailhead. I'm currently doing the project for the Lightning Superbadge and have been running into the following error when I try to reload the page for the standalone app:
 
Unable to find action 'getBoatTypes' on the controller of c:BoatSearchForm
Failing descriptor: {c:BoatSearchForm}

I've googled around and have found a lot of examples of this error where people hadn't added the @AuraEnabled annotation to their server-side controller, so the client-side controller couldn't find the method.

But, I have added that annotation and am still getting the message. It's driving me up the wall. I haven't had this issue on any other controllers I've created, and I even have another method in the same server-side controller that is being referenced by the client with no issues.

Here's my client-side controller:
({
    handleInit: function(component, event, helper) {
        // Check environment can create record
        var canCreateRecord = $A.get('e.force:createRecord');
        component.set('v.canCreateRecord', !!canCreateRecord);
        
        // Get boat types to populate boat type dropdown
        var getBoatTypesAction = component.get('c.getBoatTypes');
        getBoatTypesAction.setCallback(this, function(response) {
            var state = response.getState();
            if(state === 'SUCCESS') {
                component.set('v.boatTypes', response.getReturnValue());
            } else {
                console.log('Failed with state:', state);
            }
        });
        $A.enqueueAction(getBoatTypesAction);
    },
    
	createNewBoat : function(component, boatType) {
        var boatType = component.get('v.boatType');
        
		var createAction = component.get('c.createBoat');
        createAction.setParams({
            "type": boatType
        });
        action.setCallback(this, function(response) {
            var state = response.getState();
            if(state === "SUCCESS") {
                console.log('SUCCESS');
            } else {
                console.log(state);
            }
        });
        $A.enqueueAction(createAction);
	}
})

and my server-side controller:
public class BoatSearchApexController {
    
    @AuraEnabled
    public static void createBoat(String type) {
        Boat__c boat = new Boat__c();
        if(type != null) {
            BoatType__c boatType = new BoatType__c(Name=type);
            insert boatType;
            boat.BoatType__c = boatType.Id;
        }
        insert boat;
    }
    
    @AuraEnabled
    public static List<BoatType__c> getBoatTypes() {
        return [Select Id, Name From BoatType__c];
    }
}

​​​​​​​
Best Answer chosen by Lemming
LemmingLemming
I had missed out the controller attribute of the apex:component tag for the BoatSearchForm component.
 
<aura:component controller="BoatSearchFormApexController">
    ...
</aura:component>

 

All Answers

Maharajan CMaharajan C
Hi joe,

Try this :

 handleInit: function(component, event, helper) {
        // Check environment can create record
        var canCreateRecord = $A.get('e.force:createRecord');
        component.set('v.canCreateRecord', !!canCreateRecord);
        
        // Get boat types to populate boat type dropdown
        var action = component.get('c.getBoatTypes');
        action.setCallback(this, function(response) {
            var state = response.getState();
            if(state === 'SUCCESS') {
                component.set('v.boatTypes', response.getReturnValue());
            } else {
                console.log('Failed with state:', state);
            }
        });
        $A.enqueueAction(action);
        
    },


Can you please Let me know if it helps or not!!!

If it helps don't forget to mark this as a best answer!!!


Thanks,
Maharajan.C
LemmingLemming
Hi Maharajan,

Thanks, but unfortunately just changing the variable name of the action is not the answer. We can use any variable name for the action.

Regards
Joe
LemmingLemming
Strangely, I have found that I can access both of my server-side controller methods from the 'createNewBoat' handler of my client-side controller. But I cannot access either of the server-side controller methods from the 'handleInit' handler of my client-side controller.
LemmingLemming
I had missed out the controller attribute of the apex:component tag for the BoatSearchForm component.
 
<aura:component controller="BoatSearchFormApexController">
    ...
</aura:component>

 
This was selected as the best answer
Ankur ShresthaAnkur Shrestha
i had also faced the similar issue. but the answer marked by 
Joe Lemmer was correct. i also didnt add the controller to my component. thanks
Mike ArthurMike Arthur
I used the template code from the lightning:select docs, 'Dropdown Menu with Dynamic Options' example, here - https://developer.salesforce.com/docs/component-library/bundle/lightning:select/example#lightningcomponentdemo:exampleSelectDynamic

The attributes include the property: access="PRIVATE"

I experienced the 'Unable to find action...' error.  I had already included @AuraEnabled on my Apex controller method, and specified the controller on the component.

The issue was resolved when I removed ' access="PRIVATE" ' from the attributes.
Laxmi Kanta KarLaxmi Kanta Kar

Thanks Mike Arthur for your resolution.I was looking for this from last 2 days and also included @AuraEnabled on my Apex controller method, and specified the controller name on the component . But it didn't work.

Removing the property:access = "PRIVATE" really worked.