html code

Utilizing the RemoteAction Annotation in Salesforce Apex | Reference from the Salesforce Apex Developer Guide

Similar to Java annotations, an Apex annotation alters the usage of a method or class. Annotations commence with the ‘@’ symbol followed by the relevant keyword. To include an annotation within a method, indicate it immediately prior to the declaration of the method or class. For instance:

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

In this article, we will be exploring the @RemoteAction Annotation.

Annotation for RemoteAction:

The RemoteAction Annotation enables JavaScript to call Apex methods within Visualforce. This is often known as JavaScript remoting. Within Salesforce, the remote action function permits users to utilize JavaScript methods to invoke methods from any class. The outcome is then provided as a JavaScript object, allowing for subsequent manipulation.

Syntax: Precede the method definition with @RemoteAction.

Public Method A () {
    //Apex Code Logic

Note: The method must also have the Global or Public and Static access modifiers.

Example of RemoteAction 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;

VF 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 --->