Apex and Visualforce Controllers - Salesforce Exam DEV-501: Page Reference and Action Execution

<apex:commandLink> Component: Action Execution and Navigation

Question

A link that executes an action defined by a controller, and then either refreshes the current page, or navigates to a different page based on the PageReference variable that is returned by the action.

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

To add request parameters to an <apex:commandLink>, use nested <apex:param> components.

Answers

Explanations

Click on the arrows to vote for the correct answer

A. B. C. D.

C.

The correct answer is C. apex:commandLink.

The apex:commandLink component creates a link that executes an action defined by a controller, and then either refreshes the current page, or navigates to a different page based on the PageReference variable that is returned by the action.

It is important to note that an apex:commandLink component must always be a child of an apex:form component. This is because the apex:form component is used to define the form that contains the input fields, buttons, and other components that are used to collect data from the user and submit it to the server.

To add request parameters to an apex:commandLink, use nested apex:param components. The apex:param component is used to pass parameters to the controller method that is executed when the link is clicked. The value of the apex:param component is set to the value that is passed to the controller method.

For example, the following code creates a link that calls the 'myControllerMethod' method in the controller when it is clicked, passing the parameter 'paramValue' with the value of 'myParamValue':

php
<apex:commandLink action="{!myControllerMethod}"> <apex:param name="paramName" value="paramValue" /> Link Text </apex:commandLink>

In summary, the apex:commandLink component is used to create a link that executes a controller action and either refreshes the current page or navigates to a different page based on the PageReference variable that is returned by the action. It must always be a child of an apex:form component and can pass parameters to the controller method using nested apex:param components.