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
Renu anamalla 17Renu anamalla 17 

can you tell me Realtime Scenario for Action function ?please

can you tell me Realtime Scenario for Action function ?please
NagendraNagendra (Salesforce Developers) 
Hi Renu,

What is Action Function in Salesforce?

It's 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 javascript?

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.

Let's take an Example and work on it:

You have a checkbox and you are calling a 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 the 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:
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;
    }

}
User-added image
User-added image

For more information please check with below link. Hope this helps.

Please mark this as solved if the information helps.

Thanks,
Nagendra