Skip to main content

Visualforce actionFunction Component

About Us
Published by admin
11 May 2015
343

ActionFunction is a component, which provides support for invoking controller action methods directly from JavaScript code with the use of AJAX request.

An <apex:actionFunction> component must be a child of an <apex:form> component.

Unlike <apex:actionSupport>, which only provides support for invoking controller action methods from other Visualforce components, <apex:actionFunction> defines a new JavaScript function which can then be called from within a block of JavaScript code.

Beginning with API version 23 you can't place <apex:actionFunction> inside an iteration component — <apex:pageBlockTable>, <apex:repeat>, and so on. Put the <apex:actionFunction> after the iteration component, and inside the iteration put a normal JavaScript function that calls it.

If we want to use actionFunction, the first step is setting off a name (name=”MyActionFunction”). It is the only required attribute in this component. When we want to call our function, we call it by name.

Next step is to set action. The action method is invoked when the actionFunction is called by a DOM event elsewhere in the page markup. Use merge-field syntax to reference the method. For example, action="{!save}" references the save method in the controller. If an action is not specified, the page simply refreshes.

Attribute rendered can be used to activate or to deactivate your actionFunction. You can use a formula here.

Attribute reRender helps us to update only chosen (by id) parts of the page when the action is completed.

With help of oncomplete it is possible to set, what will happen next.

The JavaScript is invoked when the onbeforedomupdate event occurs – that is when the AJAX request has been processed, but before the browser's DOM is updated.

In the timeout we can set the amount of time (in milliseconds) before an AJAX update request should time out.

Attribute namespace helps you to set necessary namespace for your function, but if this attribute is not added, the namespace will be generated automatically.

Like in most other components, you can set id for your actionFunction and allow the actionFunction component to be referenced by other components in the page.

In focus attribute you can put the ID of the component that is in focus after the AJAX request completes.

Attribute status is the ID of an associated component that displays the status of an AJAX update request.

Setting immediate="true" we can specify whether the action associated with this component should happen immediately, without processing any validation rules associated with the fields on the page.

<!-- Page: -->

visualforce

/*** Controller ***/

visualforce


Question to the expert

We have available resources to start working on your project within 5 business days

1 UX Designer

1 Admin

2 QA engineers

1 Consultant

Related Articles
All articles
Salesforce
IoT
Native IT Service Management solution for Salesforce®
There are numerous ITSM options on the market, the most prominent of which are: Freshservice, ServiceNow, BMC Remedy, SolarWinds Service Desk, and so on. They are all outside of the Salesforce system, necessitate additional user training, and have the potential to complicate the business process. As a result, many Salesforce clients seek native ITSM Salesforce solutions to consolidate all processes on a single platform. This was a project for our group.
20 September 2022
7 reasons Why you should attend Dreamforce 2022
Have you ever wanted to be a part of a big community of like-minded people united by common goals, and values, passionate about learning new things, making friends, sharing experiences and simply having fun? We bet you have. That is what Dreamforce is about! We get that it may not be physically that easy to attend the event but it may be as hard to have enough spare time and motivation to watch it online. Here are 7 reasons why you should become a part of the biggest Salesforce event of the year.
20 September 2022
10 Effective ways to upsell Salesforce® to existing customers
When many companies look to increase their revenue, it's important to work with your most valuable potential market: your current customers. Given that acquiring a new customer costs 5 to 25 times more than retaining a current one, working on upselling and cross-selling is a much more profitable way to grow your business.
01 September 2022