Newer Version Available
Cookie Class
Namespace
Usage
- The Cookie class can only be accessed using Apex that is saved using the Salesforce API version 19 and above.
- The maximum number of cookies that can be set per Lightning Platform domain depends on your browser. Newer browsers have higher limits than older ones.
- Cookies must be less than 4K, including name and attributes.
For more information on sites, see “Salesforce Sites” in the Salesforce online help.
Example
The following example creates a class, CookieController, which is used with a Visualforce page (see markup below) to update a counter each time a user displays a page. The number of times a user goes to the page is stored in a cookie.
Cookie Constructors
The following are constructors for Cookie.
Cookie(name, value, path, maxAge, isSecure)
Signature
public Cookie(String name, String value, String path, Integer maxAge, Boolean isSecure)
Parameters
- name
- Type: String
- The cookie name. It can’t be null.
- value
- Type: String
- The cookie data, such as session ID.
- path
- Type: String
- The path from where you can retrieve the cookie.
- maxAge
- Type: Integer
- A number representing how long a cookie is valid for in seconds. If set to less than zero, a session cookie is issued. If set to zero, the cookie is deleted.
- isSecure
- Type: Boolean
- A value indicating whether the cookie can only be accessed through HTTPS (true) or not (false).
Cookie Methods
The following are methods for Cookie. All are instance methods.
getDomain()
Signature
public String getDomain()
Return Value
Type: String
getMaxAge()
Signature
public Integer getMaxAge()
Return Value
Type: Integer
getName()
Signature
public String getName()
Return Value
Type: String
getPath()
Signature
public String getPath()
Return Value
Type: String
getValue()
Signature
public String getValue()
Return Value
Type: String
isSecure()
Signature
public Boolean isSecure()
Return Value
Type: Boolean