I'm refactoring an embedded Visualforce page for a Lightning upgrade project. Previously an error message was passed via a URL parameter, but that no longer works due to an additional redirect (apparently as Lightning handles Classic URLs--not by us), so I'm setting the value on a cookie. I can see that the cookie is being set as expected on the embedded frame with the prefix apex__
and the URL-encoded message as a value.
setCookie('errorMsg', errorMessage); // cookie name ends up as 'apex__errorMsg'
private void setCookie(String name, String msg) {
if (msg != null) {
Cookie errorMsgCookie = new Cookie(name, msg, null, -1, false);
ApexPages.currentPage().setCookies(new Cookie[] {errorMsgCookie});
}
}
I'm trying to retrieve that value in the class constructor and it comes back null.
this.errorMsgCookieVal = getCookieVal('errorMsg');
private String getCookieVal(String name) {
Cookie cookie = ApexPages.currentPage().getCookies().get(name);
System.debug('updating cookie named: ' + name);
return cookie == null ? null : cookie.getValue();
}
Do I have an issue with mismatched page refs? Does that matter? I noticed that the HttpOnly
, Secure
, and SameSite
values aren't populated on that cookie, whereas the other cookies have those values. Is that an issue?
It's also maybe worth mentioning that the parent page and embedded pages are on different subdomains, respectively:
blah--lightning.lightning.force.com
blah--lightning--c.visualforce.com
Thanks.