1. URL Parameters :
How it works : You append parameters to the end of the Visualforce page URL using a question mark (?) to start, and ampersands (&) to separate multiple parameters.
/apex/MyPage?param1=value1¶m2=value2
In Visualforce: Use {!$CurrentPage.parameters.paramName}
to access the parameter values.
2. <apex:param>
Tag :
How it works: Use this tag within <apex:commandLink>
or <apex:commandButton>
to pass parameters when navigating between Visualforce pages.
In Visualforce: The destination page can then retrieve these parameters using {!$CurrentPage.parameters.paramName}
.
3. Apex Controller :
How it works: You can pass parameters to an Apex controller method through URL parameters or within <apex:actionFunction>
.
In Apex: Use ApexPages.currentPage().getParameters().get('paramName')
to retrieve the parameter values.
Important Considerations:
Example: Passing parameters through URL
Visualforce Page :
<apex:page controller="MyController">
<apex:outputLink value="/apex/AnotherPage?name=John&age=30">
Click here to go to another page
</apex:outputLink>
</apex:page>
Apex Controller :
public class MyController {
// ...
}
Another Visualforce Page :
<apex:page controller="AnotherController">
Name: {!name}
Age: {!age}
</apex:page>
Another Apex Controller :
public class AnotherController {
public String name {get; set;}
public Integer age {get; set;}
public AnotherController() {
name = ApexPages.currentPage().getParameters().get('name');
age = Integer.valueOf(ApexPages.currentPage().getParameters().get('age'));
}
}
This example demonstrates how to pass parameters through the URL and retrieve them in both Visualforce and Apex.