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
Amritesh SinghAmritesh Singh 

Creating Cookies for Standard/Custom Object

HI All,

 

 

I need to Create cookies for Standard/Custom Object. Is it possible??

 

Basically what i want,is to store an Opportunity name in cookie after the save and use that cookie to populate Opp. Name to some other Object before insert..

 

Thanx in Advance

 

joshbirkjoshbirk

Yes, you can get and set Cookies in Apex for you Visualforce Controller.  A la:

 

public PageReference setCookies() {
		//Cookie = new Cookie(String name, String value, String path, Integer milliseconds, Boolean isHTTPSOnly)
		Cookie companyName = new Cookie('accountName','TestCo',null,315569260,false); //10 year cookie
		ApexPages.currentPage().setCookies(new Cookie[]{companyName});

		return null;
	}

	public String getCookieValue() {
		return ApexPages.currentPage().getCookies().get('accountName').getValue();
	}

 So what you need is a piece of VF which you insert where the user is going through the flow you describe.