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
TBahriTBahri 

Salesforce Session variables, set and get variables in Session

I want to be able to read / write some variables to the current session in my Salesforce site pages.

I have a site built using Salesforce Sites, I need to store/retrieve some values across all the pages (consider that I am building something similar to a shopping cart). However I cant find any good example on how to read and write variables to the session (anonymous user).

 

I am using Visualforce pages with "several controllers" built in Apex.

 

I also went through this question:

http://forums.sforce.com/t5/Visualforce-Development/Storing-and-Accessing-of-Session-variables-in-APex-Page-aswell/m-p/153871

 

The suggested solutions are not valid:

1- Using cookies is not possible, I want more secure place to store the values.

2- Using the same controller also is not possible, I have dozens of pages, i cant use the same controller for them all

3- Using the custom settings seems not valid too, as they are not built for such things

paul-lmipaul-lmi

Salesforce doesn't support session manipulation at all.  The options that aren't acceptable are really the only feasible compromises you have other than not using Sites.  I'd suggest logging/voting Ideas on the idea exchange to get what you want on this front.

Ryan-GuestRyan-Guest

If you want to do this for the anonymous user, the most common practice is to use Cookies.

 

If this is something secure, then you should be authenticating each user and using HTTPS.

 

Out of curiousity, what about cookies isn't secure for you? This is how most shopping carts work.