1

We have a managed package and are attempting to set a cookie using Apex code as follows:

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

The cookie seems to be set correctly in Opera, Firefox, IE, and Chrome, but Safari doesn't seem to take the cookie. No error messages, the cookie simply doesn't show up. We've tried in several different Safari versions but no dice.

Has anyone experienced this?

  • 1
    One quick question what version of Safari/Platform ? – JamesKn Feb 4 '16 at 18:09
  • 1
    @JamesKn Latest version of Safari (9) but also tested back to 7. SF developer edition. – emroc Feb 4 '16 at 18:15
  • 1
    What are the settings in Safari for cookies? Always Allow? – cricketlang Feb 25 '16 at 19:02
  • Default settings. – emroc Mar 1 '16 at 17:34
1

I tested again the cookie set on a visual force page running on Safari and to cookie seems to set correctly.

enter image description here

I didn't use managed package to test so maybe there is still a difference there, but could you test it in the developer org where you build your package and run it there does it give the same result?

This is the code i used (standaard workbook help article code)

public with sharing class testCookieController {

public testCookieController(){

   Cookie counter = ApexPages.currentPage().getCookies().get('counter');

    // If this is the first time the user is accessing the page,
    // create a new cookie with name 'counter', an initial value of '1',
    // path 'null', maxAge '-1', and isSecure 'false'.
    if (counter == null) {
        counter = new Cookie('counter','1',null,-1,false);
    } else {
    // If this isn't the first time the user is accessing the page
    // create a new cookie, incrementing the value of the original count by 1
        Integer count = Integer.valueOf(counter.getValue());
        counter = new Cookie('counter', String.valueOf(count+1),null,-1,false);
    }

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


}

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.