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
Pradip Kr. ShuklaPradip Kr. Shukla 

Any Idea on storing data in session on Salesforce public sites?

Hi Guys,

While developing visualforce pages for public sites i want to store some values in session from apex controller.
I used Cache.Session / Cache.SessionPartition but this is only working internally, not working on public sites.

Code lines are below-
Cache.SessionPartition sessionPart = Cache.Session.getPartition('local.myPartitionSession');
 // Retrieve cache value from the partition
 if (!sessionPart.contains('BookTitle')) {
        sessionPart.put('BookTitle', 'test');

Pradip Shukla
Amit Singh 1Amit Singh 1
Hi Pradeep,
You need to use cookie class instead of Cache.Session/Cache.SessionPartition.

Refer below link for more info.

Let me know if this helps :)

Amit Sigh
Daisy ScottDaisy Scott
Following Details can help you for storing data in session on Salesforce public sites.....

Cookie sessionStore= new Cookie('BookTitle',test’,null,-1,false); // provide data in 'BookTitle' =’test’
           ApexPages.currentPage().setCookies(new Cookie[]{sessionStore});  //set value in cookie
          // provide that value to string variable sessionData 
          String SessionData = ApexPages.currentPage().getCookies().get('BookTitle').getValue(); 
         system.debug(‘SessionData ’+SessionData )
      Return :- SessionData  : test

Let me know if this is helpful ;)

Daisy Scott
Salesforce Consultants (