I am sure we all came to different situations where we need to pass parameters to VisualForce pages while doing Salesforce development. So I thought of putting all scenarios together in a single post with the solution approach. So without any further introduction, let’s get into the actual agenda quickly.
All about Salesforce Release Spring 21 here.
WHAT IS A PARAMETER ?
A parameter is a name-value pair which is embedded at the end of the url of a page. The first parameter always starts with ‘?’ and all the subsequent parameters start with a ‘&’.
Let’s take the below example –
- The first parameter is firstname=Sudipta where name is firstname and value is Sudipta
- The second parameter is lastname=Deb where name is lastname and value is Deb
SCENARIO 2 -PASSING PARAMETERS THROUGH COMMAND LINK OR COMMAND BUTTON
In order to pass parameters from one VisualForce page to another one, we can use command link or command button. Let’s start with an example where clicking on command link a new VisualForce Page will be displayed along with the message passed from the previous page.
First create a simple VisualForce Page – FirstPage
As you can see in this page, I have used a command link which is passing a parameter with key value pair as firstName=Sudipta to a new Page – SecondPage
So now create the second VisualForce Page – SecondPage
As you can see that SecondPage needs a controller – SecondPageController. This controller will capture the parameter passed to it and set it to a variable.
Here comes the controller – SecondPageController
In this controller, the below line is important which is used to capture the message passed from FirstPage –
firstName = System.currentPageReference().getParameters().get(‘firstName’);
With this approach, we need to keep in mind few things –
- All the parameters we are passing this way will be displayed in the page url. So if you are thinking of passing some confidential information, better not to do that. Otherwise you confidential stuffs will become public properties. 🙁
- If you want to pass something having special character like accountName as “Batman & Superman”, it will create problem. So it is always better to pass Salesforce ID or something unique identification field.
Should add the scenario in which both pages have the same controller and navigation is done by actions returning a PageReference. Data is maintained in the controller as long as the PageReferences don't have redirect= true.
Hi Joseph, I have written another post with the details you mentioned. Here is the link – http://sudipta-deb.blogspot.in/2015/08/how-to-pass-parameters-between-two.html. Please have a look and provide your feedback. Thanks.
This comment has been removed by the author.
wow.that is great information.Thanks for sharing……….
Dot Net Training in Chennai
Dot Net Training in Chennai
The blog gave me idea to pass parameter to visual force My sincere thanks for sharing this post and please continue to share this kind of post
Salesforce Training in Chennai
Thanks for one marvelous posting! I enjoyed reading it;Great post.The information was very useful.Keep the good work goin on!!
Hadoop training in chennai | Mainframe training in chennai | SAP SD training in chennai
Nice article i was really impressed by seeing this article, it was very interesting and it is very useful for me.
Article submission sites
Nice Post. Thanks for sharing. Keep updating
salesforce online training
salesforce online training India