I have a cookie that is being dropped by an external service into my web browser (for example named my_cookie), that I would like to access within Salesforce. However, according to the documentation the getCookies() method

Only returns cookies with the "apex__" prefix set by the setCookies method.

So when I try to access with the getCookies() method:

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

the counter value is null, because it expects the cookie name to be named apex__my_cookie.

My only solution is to write a on page load javascript function that would copy my_cookie into a cookie named apex__my_cookie so it's accessible in Salesforce. Is this the only way to achieve what I want to do, or is there an alternative method I can use that doesn't require the javascript hack?

  • 2
    Sounds like you've got the right solution already in mind. – Adrian Larson Dec 13 '15 at 2:54

I'd suggest that you can't do it directly in Apex for a very specific reason - Security. If you can get to any cookie then you can start to pull values that Salesforce might not always want you to have.

If you do find a way to do it in Apex without client side manipulation of the cookies, I'd suggest running it past the Salesforce security team first.

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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