Activity Forums Salesforce® Discussions What is the use of actionfunction ?

  • Deepak

    Member
    September 3, 2019 at 11:44 am

    This tag defines  JavaScript functions to be called from JavaScript code.  By using this tag you can call controllers methods from java script code using an AJAX request .

    This component must be a child of <apex:form> tag. And we cannot place this tag inside an iteration tag like <apex:pageBlockTable> & <apex:repet> now. Earlier we were able to do this.But with api version 23 we cannot place <apex:actionFunction> inside iteration tags

  • Achintya

    Member
    September 3, 2019 at 12:16 pm

    A component that provides support for invoking controller action methods directly from JavaScript code using an AJAX request. An <apex:actionFunction> component must be a child of an <apex:form> component.

    <apex:page controller="exampleCon">
      <apex:outputPanel onclick="methodOneInJavascript('Yes!')" styleClass="btn">
        </apex:outputPanel>
        <apex:form>
        <apex:actionFunction action="{!methodOne}" name="methodOneInJavascript" rerender="showstate">
            <apex:param name="firstParam" assignTo="{!state}" value="" />
        </apex:actionFunction>
        </apex:form>
    </apex:page>

    In the above visualforce page javascript method in the on-click event will call the apex controller method with the help of actionfunction.
    Apex controller. With the help of actionfunction we can able to make a call to the apex controller class.

    public class exampleCon
    {
        String uname;
        public String getUsername()
    {
            return uname;
        }
        public PageReference sayHello()
    {
            uname = UserInfo.getName();
            return null;
        }
        public void setState(String n){
            state = n;
        }     
        public String getState()
    {
            return state;
        }
       public PageReference methodOne()
    {
            return null;
        }
        private String state = 'no';
    }

     

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos