+ Start a Discussion
FastSnailFastSnail 

Has SFDC changed the way it insert cookies? Not able to insert 2 cookies not more?????

Hello everyone,
Thanks in advance for your help.  Below used to work for the past 10 years without any problem. Now, only one cookie is inserted out of the 2, unless retPag is set to null ??????.  Am I missing something?  Thanks in advance for your help.

---------------------
public without sharing class CNTes{
public CNTes(){
}
public PageReference creCoo(){
PageReference retPag;
cookie coo1 = new Cookie('coo1', 'coo1val', '/', -1, true);
cookie coo2 = new Cookie('coo2', 'coo2val', '/', -1, true);
ApexPages.currentPage().setCookies(new Cookie[]{coo1, coo2});
coo1 = ApexPages.currentPage().getCookies().get('coo1');
coo2 = ApexPages.currentPage().getCookies().get('coo2');
system.debug('CNTes.creCoo() finds coo1='+coo1+', coo2='+coo2);
retPag = null;   ///In that case, both coo1 and coo2 are inserted, as expected
retPag = new PageReference('/CNTes2'); ///In that case, only coo2 is inserted ????????
///Below in both cases, both cookie are found correctly ?????????????
CNTes.creCoo() finds coo1=System.Cookie[coo1=coo1val;path=/;expires=-1;isSecure=true], coo2=System.Cookie[coo2=coo2val;path=/;expires=-1;isSecure=true]
return retPag;
}
}
//////////////////////////////////////////////
public VOID reaCoo(){
cookie coo1 = ApexPages.currentPage().getCookies().get('coo1');
cookie coo2 = ApexPages.currentPage().getCookies().get('coo2');
system.debug('CNTes.reaCoo() finds coo1='+coo1+', coo2='+coo2);
///when retPag != null, coo1 is definitely NOT inserted????
CNTes.reaCoo() finds coo1=null, coo2=System.Cookie[coo2=coo2val;path=/;expires=-1;isSecure=false]
}
}
--------------------------------------------------
Page CNTes:
<apex:page controller="CNTes" docType="html-5.0" sidebar="false" showheader="false" >P
<apex:form>
<apex:outputPanel id="aopNul" />
<apex:commandButton value="Insert cookies" action="{!creCoo}" reRender="aopNul" />
</apex:form>
</apex:page>
---------------------------------------------
Page CNTes2:
<apex:page showHeader="false" sidebar="false" controller="CNTes" >
<apex:form>
<apex:outputPanel id="aopNul" />
<apex:commandButton value="Read cookies" action="{!reaCoo}" reRender="aopNul" />
</apex:form>
</apex:page>