• Laxmi Kanta Kar
  • NEWBIE
  • 5 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
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];
    }
}

​​​​​​​