html code

Apex’s RemoteAction Annotation | Salesforce Apex Developer Guide


An Apex annotation, similar to a Java annotation, alters the usage of a method or class. Annotations commence with a @ symbol, succeeded by the relevant keyword. To include an annotation in a method, indicate the annotation just preceding the method or class declaration. For instance:

Public class Myclass {
    Public method A () {
        //Apex code logic

This blog will cover the @RemoteAction Annotation.

Annotation: @RemoteAction

The Remote Action annotation enables the invocation of Apex methods in Visualforce through JavaScript, commonly known as JavaScript remoting. Salesforce’s remote action function permits users to access any method from any class using JavaScript methods, with the result returned as a JavaScript object for additional manipulation.

Syntax: Place @RemoteAction before defining the method.

Public Method A () {
    //Apex Code Logic

Note: The method should also be declared as Global or Public and Static.

Example of Remote Action Annotation:

Apex Class ->

Public Class MyClass {
    List<Account> AccList {get;set;}
    Public static List<Account> getList() {
        AccList = [Select Id, Name, phone from Account];
        return AccList;

Visualforce Page ->

<apex:page controller = “MyClass”> 
<apex:includeScript value="" />
<script type="text/javascript"> 
function demotask() { 
    function (result, event) { 
        //Code Logic
    }, {escape: true});
<!-- Here You can Print your Acclist List content which is now stored in Result parameter of demotask JS function --->