function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
amoldavskyamoldavsky 

Apex doesn't see cookies on first page load

Hey,

 

For some weird reason I am unable to access cookies on first page load. For instance I open an Account, I see no cookies in Apex, but I do see them all with a Javascript. After I redirect to a different page and come back I do see the cookies in Apex and Javascript. That does not make any sense at all to me...

 

I have a debug code that fires on page load before anything else does (it is set as the first Extension):

String cookieStr = '';
for(String k : ApexPages.currentPage().getCookies().keySet()) {
	cookieStr += k + ': ' + ApexPages.currentPage().getCookies().get(k).getValue() + ' || ';
}
System.debug('\n\n\nAssaf1: ' + cookieStr + '\n\n\n\n');
System.debug('\n\n\nAssaf2: ' + ApexPages.currentPage().getUrl() + '\n\n\n\n');

 Here is the output when I open an Account:

Assaf1: 




13:43:27.484 (1484955000)|SYSTEM_METHOD_EXIT|[40]|System.debug(ANY)
13:43:27.484 (1484971000)|SYSTEM_METHOD_ENTRY|[41]|ApexPages.currentPage()
13:43:27.484 (1484977000)|ENTERING_MANAGED_PKG|
13:43:27.485 (1485028000)|SYSTEM_METHOD_EXIT|[41]|ApexPages.currentPage()
13:43:27.485 (1485048000)|SYSTEM_METHOD_ENTRY|[41]|System.PageReference.getUrl()
13:43:27.485 (1485082000)|SYSTEM_METHOD_EXIT|[41]|System.PageReference.getUrl()
13:43:27.485 (1485104000)|SYSTEM_METHOD_ENTRY|[41]|System.debug(ANY)
13:43:27.485 (1485109000)|ENTERING_MANAGED_PKG|
13:43:27.485 (1485116000)|USER_DEBUG|[41]|DEBUG|


Assaf2: /apex/zoominfodev__ZoomAccountProfile?id=001d000000Ctfjl&inline=1


 

Because the cookies are "invalud" (do not exist) I have to forward the user to a Login page where these cookies are recreated and re-saved. Here is how:

String callbackUrl = ApexPages.currentPage().getParameters().get('callbackUrl');
PageReference callbackPage = new PageReference(callbackUrl);
callbackPage.setRedirect(true);
callbackPage.setCookies(ApexPages.currentPage().getCookies().values());

 

I then redirect back to the page I came from (Account page based on the callbackUrl) and then I do see the cookies both under Apex and Javascript. Debug output:

14:22:06.521 (521708000)|USER_DEBUG|[40]|DEBUG|


Assaf1: ziid: mYf-cYbIJ9SMVeMyK1jsCkn1hbjgRseBvXQ5YMGfvTQ4wz67jKUtC3DVoDRZZcNMrUXyDyOFx50T-pBjh0Bpfg || zisession: dIFsqCKSyDHHQSn0bool0PkIceMmqWnHOzVJdL0KlxWBdBJtm853v3DVoDRZZcNMrUXyDyOFx53u2_RkupKuSu6DxxY_-6kS3rv18myyAzP9uh-aWEhH8Qp451OiK57LLRHFCHYawdkd-OOEoZBojCcvakbGt2L4eRsgTnrpHcM || 




14:22:06.521 (521727000)|SYSTEM_METHOD_EXIT|[40]|System.debug(ANY)
14:22:06.521 (521744000)|SYSTEM_METHOD_ENTRY|[41]|ApexPages.currentPage()
14:22:06.521 (521750000)|ENTERING_MANAGED_PKG|
14:22:06.521 (521805000)|SYSTEM_METHOD_EXIT|[41]|ApexPages.currentPage()
14:22:06.521 (521827000)|SYSTEM_METHOD_ENTRY|[41]|System.PageReference.getUrl()
14:22:06.521 (521870000)|SYSTEM_METHOD_EXIT|[41]|System.PageReference.getUrl()
14:22:06.521 (521895000)|SYSTEM_METHOD_ENTRY|[41]|System.debug(ANY)
14:22:06.521 (521900000)|ENTERING_MANAGED_PKG|
14:22:06.521 (521907000)|USER_DEBUG|[41]|DEBUG|


Assaf2: /apex/zoominfodev__ZoomAccountProfile?id=001d000000Ctfjl&inline=1%3Fid%3D001d000000Ctfjlinline%3D1




14:22:06.521 (521917000)|SYSTEM_METHOD_EXIT|[41]|System.debug(ANY)

 

 

 

Any ideas why I don't get those cookies when I open the Account the first time arround?

this surely smells like a bug