• #19893
    Salesforce | Manpreet Manpreet #228
    Forcetalks

    Difference between JavaScript Remoting and ActionFunction in Salesforce?

    Difference between JavaScript Remoting and ActionFunction?

     

    #19901
    Forcetalks

    Hello Manpreet,

    ACTION FUNCTION:

    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.

    REMOTE ACTION:

    @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.]controller.method(
    [parameters…,]
    callbackFunction,
    [configuration]);

    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.

    #41455
    Forcetalks

    Hello,

    @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.
    Explanation:-
    —————-
    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.

    Thanks.

Viewing 3 posts - 1 through 3 (of 3 total)

Please to reply to this topic.

CONTACT US

We're not around right now. But you can send us an email and we'll get back to you, asap.

Sending

About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2019 Forcetalks. All Right Reserved.

Log in with your credentials

or    

Forgot your details?