One of the common problems in using force.com sites is how to pass data between authenticated site pages and non authenticated sites pages. Let us say there is a language button on the home page for the users to choose the preferred language on the website. We want the users to click the button and then transfer the language preference to all the pages in the website whether it is public or authenticated.How do we do it?
What do we know
a. When a user is logged in successfully , force.com site would create a new session and a new instance for your controllers. This would erase all data which you plan to pass as query strings.So this will not work .
a. Use the site.login method to pass parameters.
//Create the Url with query string
landingUrl = '/apex/landingPage' +'?UserId='+currentACSUserId + '&pageName='+driverNextPage;
//Create a custom object and store lang preference
lstAcsUser = [Select Language__C from Custom_object__c where ACS_ID__c=: userID_str ];
if(lstAcsUser.size() > 0)
for(Custom_object__c acUserData: lstAcsUser)
acsUserDataUpd = acUserData;
acsUserDataUpd.Language__C = viewstateController.language;
//Send landingUrl with querystrings to the login page
return Site.login(viewstatecontroller.userID_str, viewstatecontroller.password_str,landingUrl);
In the above code, I use 2 techniques to send data.
a. Create a query string with required parameters and pass the url to the login method . Read the query string on the landing page controller where the login method would redirect after successful login. Read the query string variables on the landing page controller and set language preference.
b. Create a custom object and store the preferred language in it. We might have to use a unique id to associate users and once the user logs in. This could be username which can work as a common id to associate user standard object and your custom object. Use the same user id to query the custom object and update language preference on pages after the user logs in.
Using the above 2 solutions would help to pass data between pages. Please feel free to comment your thoughts on this and i would be glad to help.
Subscribe to our mailing list and get tips to maximize salesforce to your email inbox.
Thank you for subscribing.
Something went wrong.