Activity Forums Salesforce® Discussions What is difference between Action support and Action function in Salesforce?

  • Deepak

    Member
    September 25, 2019 at 7:48 am

    1. Both action support and action function can be used to call a controller method using an AJAX request.
    * for example call controller onclick of a inputcheck box
    * or call a controller method onfocus of a input field
    Well, they both do the same thing of calling controller method.

    Difference between both:

    1. Action function can call the controller method from java script.
    2. Action support adds AJAX support to another visualforce component and then call the controller method.
    for example:

    <apex:outputpanel id="outptpnl">
    <apex:outputText value="click here"/>
    <apex:actionSupport event="onclick" action="{!controllerMethodName}"  rerender="pgblck" />
    </apex:outputpanel>

    Here action support adds AJAX to output panel, so once you click on output panel controller method will be called.

    3. Action function cannot add AJAX support to another component. But from a particular component which has AJAX support(onclick, onblur etc) action function can be called to call the controller method.
    Example:

    <apex:actionFunction name="myactionfun"  action="{!actionFunMethod}" reRender="outptText"/>
    <apex:inputcheckbox onclick="myactionfun" />

    In this example onlick of input checkbox "myactionfun" action function is called from where controller method "actionFunMethod" gets called.
    Apart from this, the main difference between the "two" action support and action function is that, the action function can also be called from java script.
    Example:

    <apex:actionFunction name="myactionfun"  action="{!actionFunMethod}" reRender="outptText"/>
    <apex:inputcheckbox onclick="myJavaMethod()" />
    <script>
    function myJavaMethod(){
    myactionfun();// this call the action function
    }
    </script>

  • Laveena

    Member
    September 25, 2019 at 7:49 am

    Difference between both:

    1. Action function can call the controller method from java script.
    2. Action support adds AJAX support to another visualforce component and then call the controller method.
    for example:

    <apex:outputpanel id="outptpnl">
    <apex:outputText value="click here"/>
    <apex:actionSupport event="onclick" action="{!controllerMethodName}"  rerender="pgblck" />
    </apex:outputpanel>

    Here action support adds AJAX to output panel, so once you click on output panel controller method will be called.

    3. Action function cannot add AJAX support to another component. But from a particular component which has AJAX support(onclick, onblur etc) action function can be called to call the controller method.
    Example:

    <apex:actionFunction name="myactionfun"  action="{!actionFunMethod}" reRender="outptText"/>
    <apex:inputcheckbox onclick="myactionfun" />

    In this example onlick of input checkbox "myactionfun" action function is called from where controller method "actionFunMethod" gets called.
    Apart from this, the main difference between the "two" action support and action function is that, the action function can also be called from java script.
    Example:

    <apex:actionFunction name="myactionfun"  action="{!actionFunMethod}" reRender="outptText"/>
    <apex:inputcheckbox onclick="myJavaMethod()" />
    <script>
    function myJavaMethod(){
    myactionfun();// this call the action function
    }
    </script>

    Here onclick of the inputcheck box java script is called from where the action function gets called and ultimately your controller method.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos