Thursday, September 13, 2018

Action function in salesforce

  • With action function you can directly invoke the controller method from javascript function using ajax request.
  • Action function  must be called from javascript function or from a client side event such as onclick.

<apex:actionFunction name="somename" action="{!callControllerMethod}" reRender="someid"/>

Let's take an example for creating contact,

Visualforce page:

<apex:page controller="createcontact">
  function javascriptmethod()      // javascript method
  createcon();                                       //  calling action function
  alert('contact created');
  <apex:form id="test">
  <apex:inputText value="{!contactname}"/>
  <apex:commandButton value="Create contact" onclick="javascriptmethod()"/>
  <apex:actionFunction name="createcon" action="{!callControllerMethod}" reRender="test"/>   //Action attribute for calling controller method


public class createcontact{
public string contactname{get;set;}

public void callControllerMethod()

contact obj=new contact();
insert obj;



Do, we visit action support function as well.

No comments:

Post a Comment