7

Hi can anybody guide me how to call a method in controller from a VF page.

2 Answers 2

8

Apex method:

public PageReference getMyMethod(){
    ....
    return null;
}

Visualforce page action function:

<apex:actionFunction action="{!MyMethod}" name="myFunction" />

actionFunction works like a javascript function, so you can call it from anywhere at your page like this:

<apex:inputField value="{!something}" onchange="myFunction()" />
10

There are two methods to do this :

1)Use @Remote Action Call to call the method

2)Use ACtion Function and call on the event

Here are the documentations for the same

http://www.salesforce.com/us/developer/docs/pages/Content/pages_js_remoting.htm

http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_actionFunction.htm

Video of demo sessions

https://www.youtube.com/watch?v=ckkChgcM9VQ

Summary :Use actionfunction if you need to maintain state between postbacks, remoteaction for stateless invocations

1
  • 6
    Use actionfunction if you need to maintain state between postbacks, remoteaction for stateless invocations. Nov 29, 2012 at 12:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .