• Ravi Jayaramappa
  • NEWBIE
  • 25 Points
  • Member since 2016
  • Software Engineer - Lightning Platform
  • Salesforce

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hello Geeks,

We are developing a Custom Lightning Community with Guest user access. We have different Custom Community pages where we have placed Lightning Component. On the first page, we allow guest to select some products and when the guest user selects a product to view the details, we want to force him a Login on the Next page.

On the 1st page, we are storing the product information in the localStorage/ sessionStorage but when rendered to login page, i want to fetch the localStorage/ sessionStorage, but when i try to fetch that record it is showing 'null' even though there is a data in the localStorage/ sessionStorage.

Below are the code snippet, i am trying to store in/fetch from localStorage/ sessionStorage

Storing Data:
var GuestShoppingCart = [];
            //for(var i=0; i<items.length; i++) {
                GuestShoppingCart.push({
                    quantity : quantity,
                    product : component.get("v.product")
                });
            //}
            console.log(GuestShoppingCart);
            sessionStorage.setItem('localCartItems', JSON.stringify(GuestShoppingCart));
            localStorage.setItem('localCartItems', JSON.stringify(GuestShoppingCart));
        }
Fetching Data (In different component on another page):
var localCart = JSON.parse(localStorage.getItem('localCartItems'));
But the later statement throws null. And I want to use that value to store in the Salesforce CRM custom object.

Can anyone point me where i am making an error. Any help is appreciated.

Thanks,
Jainam Contractor,
Salesforce Developer,
Varasi LLC
Hello Geeks,

We are developing a Custom Lightning Community with Guest user access. We have different Custom Community pages where we have placed Lightning Component. On the first page, we allow guest to select some products and when the guest user selects a product to view the details, we want to force him a Login on the Next page.

On the 1st page, we are storing the product information in the localStorage/ sessionStorage but when rendered to login page, i want to fetch the localStorage/ sessionStorage, but when i try to fetch that record it is showing 'null' even though there is a data in the localStorage/ sessionStorage.

Below are the code snippet, i am trying to store in/fetch from localStorage/ sessionStorage

Storing Data:
var GuestShoppingCart = [];
            //for(var i=0; i<items.length; i++) {
                GuestShoppingCart.push({
                    quantity : quantity,
                    product : component.get("v.product")
                });
            //}
            console.log(GuestShoppingCart);
            sessionStorage.setItem('localCartItems', JSON.stringify(GuestShoppingCart));
            localStorage.setItem('localCartItems', JSON.stringify(GuestShoppingCart));
        }
Fetching Data (In different component on another page):
var localCart = JSON.parse(localStorage.getItem('localCartItems'));
But the later statement throws null. And I want to use that value to store in the Salesforce CRM custom object.

Can anyone point me where i am making an error. Any help is appreciated.

Thanks,
Jainam Contractor,
Salesforce Developer,
Varasi LLC