function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
KMK91KMK91 

In apex class "abc" is a method how we can call using action function?

Best Answer chosen by KMK91
Amit Chaudhary 8Amit Chaudhary 8
http://sfdcsrini.blogspot.com/2014/07/visualforce-action-function-example.html
http://www.infallibletechie.com/2012/11/remoteaction-in-visual-force-page.html

Please check below example with "sayHello" method example

apex:actionFunction
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
<!-- Page: -->
<apex:page controller="exampleCon">
    <apex:form>
        <!-- Define the JavaScript function sayHello-->
        <apex:actionFunction name="sayHello" action="{!sayHello}" rerender="out" status="myStatus"/>
    </apex:form>

    <apex:outputPanel id="out">
    <apex:outputText value="Hello "/>
    <apex:actionStatus startText="requesting..." id="myStatus">
        <apex:facet name="stop">{!username}</apex:facet>
    </apex:actionStatus>
    </apex:outputPanel>
            
    <!-- Call the sayHello JavaScript function using a script element-->
    <script>window.setTimeout(sayHello,2000)</script>
            
    <p><apex:outputText value="Clicked? {!state}" id="showstate" /></p> 
            
    <!-- Add the onclick event listener to a panel. When clicked, the panel triggers
    the methodOneInJavascript actionFunction with a param -->
    <apex:outputPanel onclick="methodOneInJavascript('Yes!')" styleClass="btn"> 
        Click Me 
    </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>

/*** Controller ***/
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';
}

Please let us know uf this will help you
 

All Answers

SunidharSunidhar
<apex:actionFunction name="javascriptMethodName" action="{!abc}" rerender="something"/>
Amit Chaudhary 8Amit Chaudhary 8
http://sfdcsrini.blogspot.com/2014/07/visualforce-action-function-example.html
http://www.infallibletechie.com/2012/11/remoteaction-in-visual-force-page.html

Please check below example with "sayHello" method example

apex:actionFunction
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
<!-- Page: -->
<apex:page controller="exampleCon">
    <apex:form>
        <!-- Define the JavaScript function sayHello-->
        <apex:actionFunction name="sayHello" action="{!sayHello}" rerender="out" status="myStatus"/>
    </apex:form>

    <apex:outputPanel id="out">
    <apex:outputText value="Hello "/>
    <apex:actionStatus startText="requesting..." id="myStatus">
        <apex:facet name="stop">{!username}</apex:facet>
    </apex:actionStatus>
    </apex:outputPanel>
            
    <!-- Call the sayHello JavaScript function using a script element-->
    <script>window.setTimeout(sayHello,2000)</script>
            
    <p><apex:outputText value="Clicked? {!state}" id="showstate" /></p> 
            
    <!-- Add the onclick event listener to a panel. When clicked, the panel triggers
    the methodOneInJavascript actionFunction with a param -->
    <apex:outputPanel onclick="methodOneInJavascript('Yes!')" styleClass="btn"> 
        Click Me 
    </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>

/*** Controller ***/
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';
}

Please let us know uf this will help you
 
Amit Chaudhary 8Amit Chaudhary 8
http://sfdcsrini.blogspot.com/2014/07/visualforce-action-function-example.html
http://www.infallibletechie.com/2012/11/remoteaction-in-visual-force-page.html

Please check below example with "sayHello" method example

apex:actionFunction
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
<!-- Page: -->
<apex:page controller="exampleCon">
    <apex:form>
        <!-- Define the JavaScript function sayHello-->
        <apex:actionFunction name="sayHello" action="{!sayHello}" rerender="out" status="myStatus"/>
    </apex:form>

    <apex:outputPanel id="out">
    <apex:outputText value="Hello "/>
    <apex:actionStatus startText="requesting..." id="myStatus">
        <apex:facet name="stop">{!username}</apex:facet>
    </apex:actionStatus>
    </apex:outputPanel>
            
    <!-- Call the sayHello JavaScript function using a script element-->
    <script>window.setTimeout(sayHello,2000)</script>
            
    <p><apex:outputText value="Clicked? {!state}" id="showstate" /></p> 
            
    <!-- Add the onclick event listener to a panel. When clicked, the panel triggers
    the methodOneInJavascript actionFunction with a param -->
    <apex:outputPanel onclick="methodOneInJavascript('Yes!')" styleClass="btn"> 
        Click Me 
    </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>

/*** Controller ***/
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';
}

Please let us know uf this will help you
 
This was selected as the best answer