function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
West415West415 

Pass cookie in PageReference?

I have a small controller that I'm using and I'm trying to figure out if there is a way I can pass a cookie to a visualforce page within a PageRefernece.   I'd like the cookie to be available on my visualforce page so I can just do {!someCookieValue}.

Do I need to create another controller for the visualforce page I'm returning?

Here is the code:
 
public with sharing class pageController {

  public PageReference getTemplate() {

   Cookie someCookieValue = ApexPages.currentPage().getCookies().get('thecookie');
   return Page.HomePageTemplate;
   }

}

 
TomSnyderTomSnyder
Why not pass as parameter, then you just do   {!$CurrentPage.parameters.myparam) on the landing page
or pass data by viewstate by using a shared controller (both pages use same controller) 

If it must be a cookie, then you could use a setCookie() on the refering page and on the landing page you could prob just receive like a parameter like: {!$CurrentPage.cookies.thecookie}  (<-never tried that)  if not then you can do by controller or use ApexPages.currentPage().getCookies().get('thecookie') with controller


 
yeshabyeshab
First you need to setCookie

ApexPages.currentPage().setCookies();

and use to getCookie

Cookie someCookieValue = ApexPages.currentPage().getCookies().get('thecookie');

 
West415West415
Thanks for the replies.  Unfortunately, for this scenario we need something that will work across multiple controllers versus a shared controller where one might use in a wizard interface as an example 

I enterd up using the getCookies() and setCookies() methods as you all have suggested and it's working now!

Thanks!