2

I am currently updating some client code where information is saved via Cookies (through JavaScript). However, I am trying to find an easier way to save all the information at once, as opposed to saving them a field at a time.

Now, I have sort of a solution now where I use a @RemoteAction and save a JSON string of my current view-state and then update/load the view-state accordingly. The down-side to this is I used a custom object, which I don't think the client would go for.

So my question is the following:

How many characters can a Cookie hold?

I have an idea of simply making a Cookie manager.

The idea is to simply break up the JSON string, have one cookie to tell me the number of pieces the JSON string was broken up into, and then find the JSON string by the name it is stored under plus the number.

For example, if the JSON string is 300 characters long and you can store 256 characters per Cookie:

I want to store the cookie as "ViewState"

Cookie viewStateSizeCookie = new Cookie('ViewStateSize', '2', null, 1440, false);
Cookie viewViewStateA = new Cookie('ViewState1', '...'/*256 characters*/, null, 1440, false);
Cookie viewViewStateB = new Cookie('ViewState2', '...'/*44 characters*/, null, 1440, false);
ApexPages.currentPage().setCookies(new List<Cookie>{viewStateSizeCookie, viewViewStateA, viewViewStateB });

The only problem is, I have no idea what the max number of characters I can use for a Cookie is? Anyone know the exact amount?

2

Cookies don't have Character limit but it have size limit. as per the docs

Cookies must be less than 4K, including name and attributes. You can find more information on the docs

so i think you can store sufficient character in cookies

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.