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
Mar GeniusMar Genius 

One session(text-value) value for maintain multiple visualforce page

Hi All,  I just want to implement the one  session(text value) value across the multiple visual force pages and multiple controllers, Can anyone guide me on how to implement  
currently using cookies to maintain the one session value, is it correct?
Kancharla ChakravarthyKancharla Chakravarthy
@Mar

Please use local storage functionality to maintain values between multiple pages

Use below code in VF pages
<script>
//You can refer class variable or can set text value
var pagevar = [{onesession:'{!accid}'];
//Set the local strage
localStorage.setItem('SessionVariable',JSON.stringify(localData));

// redirect to another vf page
// no need to pass the paramaters in teh URL as local storage will hold the values till you are in vf page screens 
window.location="/VerificationLogin";
</script> 
 
<script>
  window.onload=function(){    
   // Retrieve variables from local storgae
  var retrieveData = JSON.parse(localStorage.getItem('SessionVariable'));

 //call action function and pass parameters to apex pass for furthur execution       
  setParams(retrieveData[0].accid,retrieveData[0].conid,retrieveData[0].customerFirstName,retrieveData[0].customerLastName,retrieveData[0].customerEmailAddress);
 //Clear the local storage one the operation completed
            window.localStorage.clear();
        };
    </script>

<apex:actionFunction action="{!setLocalStorageParams}" name="setParams" reRender="formId">
        <apex:param name="accountId" assignTo="{!accountId}" value="" />
        <apex:param name="contactId" assignTo="{!contactId}" value="" />
        <apex:param name="customerFirstName" assignTo="{!customerFirstName}" value="" />
        <apex:param name="customerLastName" assignTo="{!customerLastName}" value="" />
        <apex:param name="customerEmailAddress" assignTo="{!customerEmailAddress}" value="" />                
    </apex:actionFunction>

Please choose as best answer if the above code works for you. It will help others to find the best answers