Reply
Regular Contributor
KrishnakumarJ
Posts: 19
0

Storing and Accessing of Session variables in APex Page aswell in controller

How to store variables in Session and how to access that Session Variable in Apex Page & in Contoller?.
 
Regards,
KK 

Trusted Contributor
weznolte
Posts: 498
0

Re: Storing and Accessing of Session variables in APex Page aswell in controller

Hey

 

This is a bit of tricky topic as it depends on what you'd like to do and what constitutes a session for you. Unfortunately there aren't class to set session variables like you might find with JSP or PHP, but you can try a few of these options,

 

1. You can create a session if all pages involved use precisely the same controller and controller extensions. A tutorial can be found here

 

2. You could use cookies.

 

3. You could use Custom Settings, a new feature on the Platform. 

 

Cheers,

Wes 

Salesforce Tips 'n Tricks ~ The Silver Lining
Want to master the Force.com Platform? You need the Salesforce Handbook.
Regular Contributor
KrishnakumarJ
Posts: 19
0

Re: Storing and Accessing of Session variables in APex Page aswell in controller

Hi Wes, 
Thanks for your reply. I am looking the following equivalent like storing a value in Session Object in Apex Class and Retreving it in Diff  VFPage.
 
 Storing a value in Session Object :

String sessionSet="theKK"; session.setAttribute("MySession",sessionSet);

  

 Retreiving the value from Session Object  :

String getSessionValue= (String)session.getAttribute("MySession");

 

Thanks & Regards ,

 KK 



Trusted Contributor
weznolte
Posts: 498
0

Re: Storing and Accessing of Session variables in APex Page aswell in controller

Yeah I've had similar requirement before but there isn't a feature available as you've described it. I would recommended reading throught the options I've summarised, and choosing one from there. If the pages are completely different and it doesn't make sense for them to use the same controller I'd suggest using 'Custom Settings'.

 

Wes

Salesforce Tips 'n Tricks ~ The Silver Lining
Want to master the Force.com Platform? You need the Salesforce Handbook.
Regular Contributor
KrishnakumarJ
Posts: 19
0

Re: Storing and Accessing of Session variables in APex Page aswell in controller

In first Page I've selected a Organization, we need to get that selected organization in all pages similar to Session Tracking.
 
Thanks,
KK 
 

Regular Contributor
Susana NTS
Posts: 16
0

Re: Storing and Accessing of Session variables in APex Page aswell in controller

Hi all,

 

I have the same requirement as Krish.

 

The thing is that I can't see the point in using Custom Settings since, as it says in the documentation, "After you save a custom setting, you cannot change this value".

How do you plan to use that feature if you are unable to set an specific value each time a user enters the page?

 

Thanks,

 

Susana

Regular Contributor
Susana NTS
Posts: 16
0

Re: Storing and Accessing of Session variables in APex Page aswell in controller

I think this reply to another post is one of the solutions to our requiremet

http://community.salesforce.com/sforce/board/message?board.id=sites&thread.id=1519&jump=true

Contributor
TBahri
Posts: 3
0

Re: Storing and Accessing of Session variables in APex Page aswell in controller

Hi,

 

I have the same question, and the provided answers do not seems to be problem solvers.

 

  • Using cookies is not possible, I want more secure place to store the values
  • Using the same controller also is not possible, and I doubt that this solution will work in case the user hit CTRL+F5
  • I cant find any example on how to read/write to custom settings (as mentioned in one of the answers) in Apex for each anonymous user, I want each user's data to be accessible only by him