I was working on the apex controller of my first Lightning Component today, when I got an strange error message:
AuraEnabled methods must be named with a prefix 'get'
I noticed that all of the examples from the developers' guide used static methods, and often didn't start with 'get'.
When I made my method static in the controller, sure enough, the error message went away even though the method name still doesn't start with 'get'.
So, my question is, do you think the compiler was trying to warn me that the method wasn't static, and is there a reason for making all server-side methods in lightning components static?
Best Answer
It turns out that AuraEnabled methods need to be static. On page 19 of the guide (in the quick start section), it says:
It would have been nice if this was also in server-side controller overview part of the guide, or if the compiler had given a more descriptive error message.
I was able to get the controller to compile with a non-static method, but it ended up producing an error when attempting to access the method. Setting the method to static resolved the issue.
// app
// component, named TestComponent
// client-side controller
// server-side controller
// The error