Newer Version Available
AuraEnabled Annotation
- Use @AuraEnabled on Apex class static methods to make them accessible as remote controller actions in your Lightning components.
- Use @AuraEnabled on Apex instance methods and properties to make them serializable when an instance of the class is returned as data from a server-side action.
Component Security
In Apex, every method that is annotated @AuraEnabled should be treated as a web service interface. That is, the developer should assume that an attacker can call this method with any parameter, even if the developer's client-side code does not invoke the method or invokes it using only sanitized parameters. For more information, see the Secure Coding Guide.
Caching Method Results
To improve runtime performance, set @AuraEnabled(cacheable=true) to cache the method results on the client. To set cacheable=true, a method must only get data. It can’t mutate data.
Marking a method as storable (cacheable) improves your component’s performance by quickly showing cached data from client-side storage without waiting for a server trip. If the cached data is stale, the framework retrieves the latest data from the server. Caching is especially beneficial for users on high latency, slow, or unreliable connections such as 3G networks.
To cache data returned from an Apex method for any component with an API version of 44.0 or higher, you must annotate the Apex method with @AuraEnabled(cacheable=true). For example:
Prior to API version 44.0, to cache data returned from an Apex method, you had to call setStorable() in JavaScript code on every action that called the Apex method. For API version of 44.0 or higher, you must mark the Apex method as storable (cacheable) and you can get rid of any setStorable() calls in JavaScript code. The Apex annotation approach is better because it centralizes your caching notation for a method in the Apex class.
Using Continuations
Use the Continuation class in Apex to make a long-running request to an external Web service.
Continuations use the @AuraEnabled annotation. Here are the rules for usage.
- @AuraEnabled(continuation=true)
- An Apex controller method that returns a continuation must be annotated with @AuraEnabled(continuation=true).
- @AuraEnabled(continuation=true cacheable=true)
- To cache the result of a continuation action, set cacheable=true on the annotation for the Apex callback method.