Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
Apex Server-Side Controller Overview
Only methods that you have explicitly annotated with @AuraEnabled are exposed. Calling server-side actions aren’t counted against your org’s API limits. However, your server-side controller actions are written in Apex, and as such are subject to all the usual Apex limits. Apex limits are applied per action.
This Apex controller contains a serverEcho action that prepends a string to the value passed in.
1public with sharing class SimpleServerSideController {
2
3 //Use @AuraEnabled to enable client- and server-side access to the method
4 @AuraEnabled
5 public static String serverEcho(String firstName) {
6 return ('Hello from the server, ' + firstName);
7 }
8}- Methods must be static and marked public or global. Non-static methods aren’t supported.
- If a method returns an object, instance methods that retrieve the value of the object’s instance field must be public.
- Use unique names for client-side and server-side actions in a component. A JavaScript function (client-side action) with the same name as an Apex method (server-side action ) can lead to hard-to-debug issues. In debug mode, the framework logs a browser console warning about the clashing client-side and server-side action names.
For more information, see Classes in the Apex Developer Guide.