In this blog, we will learn Remote Action function in Visualforce Page. First of all, we should know, what is remote action function in salesforce. Let’s get started!

What is Remote Action function in Salesforce?

Remote action function in salesforce allows user to access any method from any class through javasrcipt methods, and get the result as a javascript object for further manipulation.

Points to remember while implementing remote action function:

  • Remote action method should have @RemoteAction annotation.
  • The method should also be Global and Static


Let’s start with controller code:

global with sharing class ContactJs {  
    * Webkul Software.
    * @category  Webkul
    * @author    Webkul
    * @copyright Copyright (c) 2010-2016 Webkul Software Private Limited (
    * @license
    public ContactJs() { } // empty constructor    

    @RemoteAction //the function to be called in remote action should use this annotation
    global static list<Contact> getcon() {
        //function should be static and global else it will throw error
        list<Contact> con1 = [SELECT id,name FROM contact limit 5];
        if(con1!=null && !con1.isEmpty()){        
            return con1;        
            return  new list<contact>();        

Now the Visualforce Page:

<apex:page controller="ContactJs">
         * Webkul Software.
         * @category  Webkul
         * @author    Webkul
         * @copyright Copyright (c) 2010-2016 Webkul Software Private Limited (
         * @license
    <script type = "text/javascript">
    function getRemoteContact() {
        var a;
            //Invoking controller action getcon
            function(result, event){
               //We can access the records through the parameter result
               //event.status determines if there is error or not 
                    document.getElementById('remoteContactId').innerHTML = 'Contact Name: <br/><br/>';
                        document.getElementById('remoteContactId').innerHTML +=  result[a].Name +'<br/>';                    
            {escape: true}

    <button onclick="getRemoteContact()">Get Contact</button>
    <div id="responseErrors"></div>
    <apex:pageBlock id="block">        
        <apex:pageBlockSection id="blockSection" columns="2">
                <span id="remoteContactId"></span>


Here is the output:


That’s all for Remote Action function in Visualforce Page, still have any issue feel free to add a ticket and let us know your views to make the code better


Leave A Reply

Please verify that you are not a robot.

Tell us about Your Company

How can we help you with your business?

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home