Showing posts with label Action Function. Show all posts
Showing posts with label Action Function. Show all posts

Wednesday, January 28, 2015

What is difference between Action function and remote function?

What is difference between Action function and remote function?

1. Using action function, you can call only same class function.
2. Remote Action returns the results from the class in Javascript.
3. Action function submit the page, Remote action doesn't

Remote Action in Visual force page:
JavaScript remoting in Visualforce provides support for some methods in Apex controllers to be called via JavaScript.

• namespace is your organization's namespace. This is only required if the class comes from an installed packaged.
• controller is the name of your Apex controller- MyJSControllers
• method is the name of the Apex method you're calling- getAccount
• params is comma–separated list of parameters that your method takes-accountNameJS
• callbackFunction is the name of the function that handles the response from the controller. It returns the status of the call and the method result.- function
• escape defines whether your response should be escaped (by default, true) or not (false)- {escape:true}

·    JavaScript remoting:
- pass parameters
- provides a callback
·        The <apex:actionFunction> tag:
- specify rerender targets
- submits the form



Sunday, August 24, 2014

What is Action Function in Salesforce?

What is Action Function in Salesforce?


Its easy to call a controller method for most of the attributes using action="{!Yourmethode_Name}", but what if you were to call the controller method from java script?

One way to do this is by using Action Function. Expertise will definitely be able to use this in complex scenarios. This post is for those who haven't had hands on action function before and want to know how to use it.

Lets take a Example and work on it:


You have a checkbox and you are calling javascript function on click of this checkbox. And now once you are in js you wish to modify some variable or do something in your controller class.

Say you want to put some value for a variable in controller and then display it on your page. this will require calling your class method from js.


Example :

Visualforce Page:

<apex:page standardcontroller="Account" extensions="ActionFunctionController" tabStyle="Account">
    <apex:form >
       <apex:actionFunction name="actionFunName" action="{!ActionFunMethode}" reRender="outputtxtId"/>
       <apex:pageBlock > 
            <apex:outputLabel for="inptCheckBox" value="Check this box to call Controller method from js using ActionFunction" style="color:green;"></apex:outputLabel> 
            <apex:inputcheckbox onclick="javaScrpt()" id="inptCheckBox"/>
       </apex:pageBlock> 
      
      <apex:outputText value="{!MyString_From_Methode}" id="outputtxtId"></apex:outputText> 
    </apex:form> 
    
    <script>
      function javaScrpt(){
       actionFunName(); 
      }
    </script>
     

</apex:page>


Controller class:

Public class ActionFunctionController {
Public string MyString_From_Methode{get;set;}

  public ActionFunctionController(ApexPages.StandardController controller) {

    }

  public string ActionFunMethode(){
     MyString_From_Methode = 'Method called from js using Action function';
     return null;
    }

}



Output:
save image


save image








 
| ,