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

Persistent Cookies with APEX

I am developing a Salesforce Sites application that has a requirement for creating a cookie that will persist if the Browser is closed and reopened.  Using the APEX Cookies class it appears that only session cookies are created.  Is this true?  Is there a recommended work-around. 


Thank you!  




Not sure when this post was made, but when you are contructing a cookie you can enter in an integer value that represents the seconds that this cookie will persist within the browser. if this is set to <0 or null it creates a session long cookie that will last only as long as the browser is open. If you want it to last for a long time you can just set the int to be some ridiculous number like 315360000 (ten years).


for example 

Cookie commonFields = new Cookie('commonFields',insertedValues,null,315360000,false) 


This does not work as whatever you set except for 0 or -1 results i n:
Sun 07 Dec 1969 03:28:36 GMT