+ Start a Discussion

Issue with setting a cookie...err: constructor not defined.

 hai everyone the following code gives an error....

I want to store a list in a cookie....

Error: prosearch Compile Error: Constructor not defined: [System.Cookie].<Constructor>(String, LIST<Product__c>, NULL, Integer, Boolean) at line 327 column 25

here is the code...

public list<Product__c> searchlist{set; get;}

 public List<Product__c> getsearchProductJava(){
         List<Product__c> searchlist = new List<Product__c>();
       qry ='select id, Product_Name__c,Price__c,Product_Image__c, Company__c from Product__C where (Product_Department__c =: selecteddept)';     
         if(selectedcat != 'none')
              qry+=  'AND (Product_Category__c=: selectedcat)';
         if(choosegender!= 'none')
               qry+= 'AND (Trending_For__c =: choosegender)';
         searchlist = database.query(qry);
         return searchlist;   

 public void setCookie() {
    Cookie userCookie = new Cookie('CookieName', searchlist, null, 315569260, false); //Here 315569260 represents cookie expiry date = 10 years. You can set this to what ever expiry date you want. Read apex docs for more details.
    ApexPages.currentPage().setCookies(new Cookie[] {

Hi Suresh,

I doubt we can pass List as 2nd parameters of Cookies constructor. Cookies constructor will look like "Cookie(String, String, String, Integer, Boolean) ".
You can find more details at https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_sites_cookie.htm.

I should suggest to keep it as string and use "," or '|' as data separater for multiple Products. YOu need to do this everything when you are setting or reading data from Cookies.