0

I have old code where VF page is doing URL redirection with appending query params in URL.

like URL="https://UatTest.com?target=FGI" - this is from label then we are appending params with this url like below

url=url+'&+''firstname='+userinfo.getfirstname()+'&'+'lastname='+'Account Number'

and so on.

in Page Refrence URL redirection is arranging most query params in alphabetical order. Like we want URL=https://UatTest.com?target=FGI?firstname='jody'&lastname=''&AccountNumber='' etc

We don't want query params to be arranged in alphabetical order, is there any way we can do this?

1
  • 2
    Why does the order of the query string parameters order?
    – Derek F
    Jun 8, 2022 at 15:12

2 Answers 2

1

Unfortunately, if you're using PageReference for your redirect, you're stuck with its behaviors and limitations. Notably, you can't include the same parameter more than once, and you cannot control the order in which the parameters get rendered. Both of these limitations stem from the fact that the parameters are parsed into a Map, which is an unordered collection of key-value pairs. If you want to redirect, you'll have to return the URL directly back to the client somehow and use JavaScript to redirect.

4
  • 1
    Or use a VF page that includes an HTML head meta redirect when the redirection is required?
    – Phil W
    Jun 8, 2022 at 15:51
  • Thanks@sfdcfox for the feedback. Is there any other work around. Jun 8, 2022 at 15:54
  • Thanks@PhilW for the feedback. can you please help as at present we are redirecting from Apex Controller on button click on submit and after some processing we want to redirect user. . Using PageRefrence page=new PageRefrence(url);.. so you are saying we can redirect user to another new VF page with head meta redirect Jun 8, 2022 at 15:56
  • @PhilW That's a good point.
    – sfdcfox
    Jun 8, 2022 at 17:34
0

When you want to do the redirect, have a VF controller property that holds a URL that is generated from the base page reference, via getUrl, to which you programmatically append your query parameters, then ensure that you have some conditional processing in the Visualforce page that creates an HTML head meta to perform a redirect. This markup is of the form:

<head>
  <meta http-equiv="refresh" content="0;url={!theRedirectURLControllerProperty}" />
</head>

You will want to make sure it is conditionally rendered only when required (e.g. when the URL property is populated).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .