Activity Forums Salesforce® Discussions Difference between JavaScript Remoting and ActionFunction in Salesforce?

  • Radhakrishna

    May 5, 2017 at 7:03 am

    Hello Manpreet,


    ActionFunction is used to execute a method in your Apex Class from within your Visualforce Page asynchronously via AJAX requests. What does asynchronous AJAX requests mean ? This means that Visualforce Pages(otherwise HTML pages when rendered at the Client Side via the Browser) can send data to, and retrieve data from, a server asynchronously (in the background) without interfering with the display and behavior of the existing page. So when we execute an Apex Method via the ActionFunction, the page is not disturbed and the request to the servers(Apex Code compiles and runs on the Salesforce servers while the Visualforce pages which are nothing but HTML pages are rendered by browser at the Client Side) are sent and received in the background. The other way of doing such AJAX requesst to Apex Methods include the Visualforce Remoting. The only difference between the same is that when using the Visualforce Remoting you will have to write some extra lines of JavaScript which is not needed in case of the ActionFunction.

    Now, a very simple and a common example of ActionFunction is mimicking the Field Dependency feature on Visualforce Pages. Say for example you had two Picklists – Select the Object and Select the Field. When a user selects an Object, the next Picklist automatically gets populated with the Fields that belong to the object.


    @RemoteAction in Visual force page
    JavaScript remoting in Visualforce provides support for some methods in Apex controllers to be called via JavaScript.

    JavaScript remoting has three parts:

    The remote method invocation you add to the Visualforce page, written in JavaScript.
    The remote method definition in your Apex controller class. This method definition is written in Apex, but there are few differences from normal action methods.
    The response handler callback function you add to or include in your Visualforce page, written in JavaScript.

    To use JavaScript remoting in a Visualforce page, add the request as a JavaScript invocation with the following form:


    namespace is the namespace of the controller class. This is required if your organization has a namespace defined, or if the class comes from an installed package.
    controller is the name of your Apex controller.
    method is the name of the Apex method you’re calling.
    parameters is the comma-separated list of parameters that your method takes.
    callbackFunction is the name of the JavaScript function that will handle the response from the controller. You can also declare an anonymous function inline. callbackFunction receives the status of the method call and the result as parameters.

  • Avnish Yadav

    September 30, 2018 at 5:05 am


    @RemoteAction is an Apex annotation used to mark a method as being available for javascript remoting. This allows you to call the method from javascript yourself and retrieve the result as a javascript object for manipulation, as per the example in the documentation. They are static and global, and hence don't have access to your current controller variables and methods.

    Action Function
    Action function used to call the server side method using JavaScript.
    ActionFunction: provides support for invoking controller action methods directly from JavaScript code using an ajax request

    Used when we need to perform the similar action on various events. Even though you can use it in place of actionSupport as well where the only event is related to only one control.


Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos