[SalesForce] How is a Cookie constructed

The documentation for the Cookie class is here:
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_sites_cookie.htm

But lacks documentation for the constructor. From code examples it looks like the constructor takes 5 parameters:

  1. String name // cookie name
  2. mixed value // cookie content
  3. ?? // normally 'null'
  4. int time // -1 for expiry with session,
    otherwise number of seconds to live
  5. boolean ?? // normally 'false'

Can someone confirm this and fill in the blanks for us?

Also, how do you know this?

Best Answer

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.

Related Topic