+ Start a Discussion
Pradip Kr. ShuklaPradip Kr. Shukla 

Any Idea on storing data in session on Salesforce force.com public sites?

Hi Guys,

While developing visualforce pages for force.com 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');
 }

Thanks.
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.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_sites_cookie.htm

Let me know if this helps :)

Thanks,
Amit Sigh
Daisy ScottDaisy Scott
Following Details can help you for storing data in session on Salesforce force.com 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 ;)

Thanks
Daisy Scott
Salesforce Consultants (http://www.janbask.com/salesforce-consulting-services/)