Working with the page parameter on the VisualForce page tab in LEX [the simpler way]

Vinod Patel
2 min readOct 3, 2020

Using the page parameter on the visualforce page in the visualforce tab in LEX.

I know the use of the visualforce page is now old school stuff, after the release of aura and LWC. But still, for some reason, you may wanna go with the visualforce page, and the reason could be you want to use CDN, and you probably know that you can’t use CDN in the aura or the LWC for some security reasons. You may wanna go with the visualforce pages.

You have created a visualforce and you also have created a tab for that visualforce page. Now you want to pass the parameter to that visualforce page and also want to make sure that the visualforce page open in the tab that you have created. To do that you probably will go with

yoursalesforcedomain.salesforceinlighting.com/lightning/n/namespace__vf_tab_name?paramter=1234

but when you redirect to this visualforce tab the parameter in the URL is removed and you have a null value in

ApexPages.currentpage().getparameters().get('paramter');

and you quickly open google.com and start typing How to use the page parameters in the visualforce page tab in LEX? and that’s why I am writing this story 😁.

I also stuck in the same problem but in my case, I was coming back to my visualforce page tab in LEX from an external source for some reason with an Id and I want that Id on the visualforce page so I can take the further action.

So let me give you my solution.

What I have done to fix this problem I created and another visualforce page and named it SetIdAndRedirect and pick the Id from the page parameter and store that Id in the cookie for that visualforce domain and simply redirect to the main visualforce tab without any parameter.

yoursalesforcedomain.salesforceinlighting.com/lightning/n/namespace__vf_tab_name

And I also add a simple message on the middleware visualforce page Redirecting…. and at a load of my actual visualforce page in the visualforce page tab, I always check for the parameter value in the cookie and take further action.

for storing the cookie you can use this W3School code 😎

function setCookie(cname, cvalue) {
var d = new Date();
d.setTime(d.getTime() + (5 * 60 * 1000));
var expires = "expires=" + d.toUTCString();
document.cookie = cname + "=" + cvalue + ";domain=" + window.location.hostname + ";SameSite=Strict; Secure;" + expires + ";path=/";
}

Hope you got the idea here. So next time if you stuck in a problem that is similar to this, you may think this as a solution.

Hope you like this small sharing. happy coding…

--

--