Newer Version Available

This content describes an older version of this product. View Latest

Apex Server-Side Controller Overview

Create a server-side controller in Apex and use the @AuraEnabled annotation to enable client- and server-side access to the controller method.

All methods on server-side controllers must be static because the framework doesn’t create a controller instance per component instance. Instead, all instances of a given component share one static controller.

Any state stored on the controller is shared across all instances of a component definition.

Warning

Only methods that you have explicitly annotated with @AuraEnabled are exposed. Other methods are not available.

This Apex controller contains a serverEcho action that prepends a string to the value passed in.

1swfobject.registerObject("clippy.codeblock-0", "9");public 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}