How is a Cookie constructed?

I have used cookies in the past, and struggled in the same way that you did. My understanding of the constructor is as follows:

Cookie cook=new Cookie('Name', 'Keir Bowden', null, 1440, false);

Where:

  • 'Name' = the name of the cookie
  • 'Keir Bowden' = the value of the cookie
  • null = the cookie path (where null results in the default location '/')
  • 1440 = the max age
  • false = is the cookie only accessible through https

Pretty sure I found this through trial and error and inspecting the HTTP messages - its still my opinion though!

I also recall that the max age didn't seem to have any effect, and I could only generate session cookies, but in the end I couldn't do what I wanted to anyway so I didn't investigate further.


langCookie = new Cookie('uLang', userLanguage, null, -1, false);
    ApexPages.currentPage().setCookies(new Cookie[]{langCookie});
    userLanguage = langCookie.getValue();

Just agreeing with Bob and this is the code that i used for one of the website development on force.com and works perfectly for me .

Tags:

Apex