Salesforce Session variables, set and get variables in Session -
i want able read / write variables current session in salesforce site pages.
i have site built using salesforce sites, need store/retrieve values across pages (consider building similar shopping cart). cant find example on how read , write variables session (anonymous user).
i using visualforce pages several controllers built in apex.
regards
custom settings cached @ application level, maybe that's why suggested in link above. i'm not sure if i'd recommend approach, might able work.
if create custom setting named "sessiondata", , add custom fields (that represent data want store in session), save data this:
database.saveresult result = database.insert(new sessiondata__c(yourfieldhere='your value here etc')); system.debug(result.getid());
then use resulting custom setting id store in cookie. while custom settings can accessed using normal soql, advantage data cached , can accessed this:
if (sessiondata__c.getall().containskey('unique id cookie here')) { system.debug(sessiondata__c.getinstance('unique id cookie here').yourfieldhere); }
keep in mind custom settings weren't designed this, you'll need periodically purge old custom settings data, normal session management systems do.
see apex custom settings documentation more details.
Comments
Post a Comment