i have two params in apex,
errorNum = 1; errorMessage = System.Label.UPL_OFFMSG_OfferExist;
now,i want to redirect from the current page to another,but the param will lost in the next page.
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.Sign up to join this community
The key to this is to use the
PageReference class and in particular the
I will make the presumption that the page you are trying to redirect to is a VF page called NextPage.
The first step is to get a PageReference reference for that page using
PageReference pr = Page.NextPage;
You can now make use of the goodness of the PageReference class as documented in the Salesforce docs.
The method that we're interested in is the getParameters() method. As you can see from the documentation this returns a map of parameters that you can add to. Which means you can add your variables to the map to make sure they are passed as parameters in the URL:
pr.getParameters().put('errorNum', errorNum); pr.getParameters().put('errorMessage', errorMessage);
The PageReference class then converts these parameters to Key Value pairs in the query string of the URL that it builds.
If you want to force the browser to do a client side redirect (use GET rather than POST) then use
pr.setRedirect(true); and then return the Page Reference from your method.
A small note: If you're redirecting to an external page you will need to construct the PageReference by using the target URL. And in this case the browser will always be forced to do a redirect, so
setRedirect become superfluous.