Introduction
JavaScript is the dynamic scripting language that performs actions on the client side. With the help of JS, it is possible reducing traffic on the web server. There are two popular Apex functions the Salesforce -
An
Based on the API version 23, it is not possible using
Before we move to the apex attributes, if you are seriously planning to begin your career in Salesforce should think about going for a Salesforce Cloud Course to land their career on the right path.
-
Attribute name -
This attribute is invoked when the actionFunction is called by the DOM event elsewhere in the page markup. You may use merge-field syntax for method referencing. For example, action = “{save}” references the save method in the controller. When an action is not specified, the page refreshes automatically.
- Attribute name -
It represents the ID of the omponent that is in focus when AJAX request completes.
- Attribute name -
It is an identifier that allows the actionFunction component to be referenced by other components in the page.
- Attribute name -
It is a Boolean value that specifies whether the action associated with the component should happen immediately or not. It does not any validation rules associated with fields on the page. If it is set to true then action happens immediately and validation rules are skipped automatically. If there is no value defined for the attribute then it is set to false by default.
- Attribute name -
It includes the name of JavaScript function when the function is executed somewhere else in the page markup causes the method specified by action attribute to execute. As soon as the action method completes, the components specified by the reRender attribute are refreshed.
- Attribute name -
The namespace is used for the generated JavaScript function. The attribute of namespace should be a simple string, beginning with a letter and consists of only letters, numbers, or the underscore character. For example, your app_name_version is supported as namespaces. If no namespace is added to the JavaScript functions that are generated by the
- Attribute name -
The JavaScript function invoked when the result of an Apex update request completes on the client.
- Attribute name -
It includes the Boolean value that specifies whether the component is rendered or not on the web page. If not specified, the value is set to true by default.
-
Attribute name -
It shows the ID of one or more components that are redrawn when the result of the action method returns to the client. The final value can be an individual ID, a comma-separated list of multiple IDs, a merge field expression for the list of the collection of IDs.
- Attribute name -
It is the ID of an associated component that displays the status of an AJAX update request.
- Attribute name -
It shows the amount of time in milliseconds before an AJAX request should time out. Meanwhile, we recommend you to go through various Salesforce blogs available on the JanBask Training which may really increase your knowledge and answer your queries related to Salesforce.
Next, we will check the need for action tags in Salesforce.
Why Action Tags are Needed in Salesforce?
It is possible creating Visualforce pages by invoking controller methods using AJAX requests. There is the case you want to use AJAX in the Visualforce page so that a particular part of the page can be refreshed and performs specified actions when the user clicks on a button. We can use multiple action tags in this case that are supported by the AJAX request.
This action tag must be called from the client-side event or from a custom JavaScript function. It generally behaves like any other JavaScript function that has the capability to communicate with server methods using the “action” attribute. Keep in mind that action attribute is optional here that should be used when required. This action tag can also refresh the VF function on the client-side event using the reRender attribute.
This action tag adds AJAX support to another Visualforce component and then call the controller method. For example, we wanted to implement the search functionality where we need instant results for each keyword that matches the content. Here, we need to add AJAX support to the InputText that calls a function and returns the needed result.
This action tag acts as the timer on the Visualforce page. It is used to send the AJAX request to the server depending on the time interval. In case, the time span is not specified then it is taken 60 seconds by default.
For example, we want to update the account list in every 5 seconds. It will show every new account on the Visualforce page as soon as added. It is clear from the discussion that this action tag is used for the component that we want to refresh in every few seconds. If you don’t want to refresh the component frequently then you should use
These were the tags required in Salesforce. Now, we will go through the process of passing parameters between Apex and Visualforce.
Tip: The top customer relationship management (CRM) platform in the world is Salesforce. Take this free, 2-minute Salesforce quiz to see how much you know about the platform and to keep up with new developments.
How to Pass Parameters Between Apex and Visualforce?
When the user clicks a link, we want to pass the ID to the Apex method. The APEX method then returns to us a URL string. We open a new window here that loads that needed URL. We can call parameters and variables from Visualforce pages but passing parameters or variables to and forth between Apex methods and Visualforce is not intuitive. However, it is impossible passing parameters from a Visualforce page to the Apex method directly.
- Not Supported: It is possible calling Apex method from a Visualforce page directly if parameters are required.
- Supported: It is possible calling Apex method from a Visualforce page if there are no parameters.
So, how to pass the ID parameter to the Apex method from the Visualforce page. Well, Apex class is the solution here that help to initialize variables outside the method since parameters cannot be passed from Visualforce page directly. We need to declare actionFunction here that works similar to the Apex method. When you call this action tag, you are free to add multiple parameters between Apex and Visualforce methods here.
Also, consider joining the JanBask Salesforce community to keep yourself updated with the latest Salesforce trends and career opportunities.
Conclusion
With this discussion, you must be sure of what is Apex:actionFunction method and how it helps in multiple ways to invoke controller methods using different action control attributes. There are more similar methods too that are also discussed in brief because the main objective of this blog is to discuss the concept of Apex:actionFunction in detail. To know more about tough Apex methods and controllers, join the Salesforce certification program and learn to use different control tags practically with the right experts’ assistance.