Coder Social home page Coder Social logo

read-write-cookies-in-salesforce's Introduction

How to Read/Write cookies in Salesforce

What are Cookies ?

Cookies are small files which are stored on a user's computer. They are designed to hold some amount of data specific to a particular client and website, and can be accessed either by the web server or the client computer. In simple we can say that Its a small memory to store some information for some interval of time. Generally we use this to store user's preferences for a particular website.

Storing Content in Cookies in Salesforce:

In Salesforce we have Cookie class which is used to create Cookie.

Cookie cookie = new Cookie('WPDEMO',enteredCookieData,null,-1,false);

In Cookies constructor we pass :

First Parameter : Cookie Key Second Parameter : Cookie Key's Value Third Parameter : Path Fourth Parameter : Maximum Age Fifth Parameter : isSecure

Once we create Cookie object we can set this cookie with Current Page so that anyone who access url with same domain can access the cookie.

ApexPages.currentPage().setCookies(new Cookie[]{cookie});

We set the created cookie on current page.

Reading Content in Cookies in Salesforce:

To read cookie we have to get all cookies on current page. And from that cookies map we can get our cookie by using the name we have used while creating cookie.

Cookie cookie = ApexPages.currentPage().getCookies().get('WPDEMO');

This will return Cookie object and from that object we can get value by getValue() method. This will return value of that cookie.

cookieValue = cookie.getValue();

To know more about, refer to my blog post @ http://blog.singhtarandeep.com/blog/2017/08/17/readwrite-cookies-salesforce/

read-write-cookies-in-salesforce's People

Contributors

tdssaini avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.