+ Start a Discussion

Control the order of the parameters in a PageReference?

I have a page which does some checks and if everything looks good it redirects the user to another webpage outside of salesforce and it passes some info in the URL.  I am using the "action" property of the page which works really well for this sort of thing.  The problem is that when I define a PageReference, and then redirect the browser, the parameters are in alphabetical order instead of the order I defined them.  So for instance:


1.  I define a new PageReference('https://www.mycoolurl.com?Bparam=Bval&Aparam=Aval')

2.  Use action to call function which returns my PageReference

3.  Browser goes to 'https://www.mycoolurl.com?Aparam=Aval&Bparam=Bval'


This is not a problem with salesforce pages because it doesn't care about the order, but unfortunately the address is to an older more rigid system which I have little control over and it expects the parameters in a certain order.


Any way I can control the order?  I really hope so, because otherwise I am going to have to use some workaround that will involve JavaScript redirects or something, which usually leads to a lot more support issues.


I think the problem here is that PageReference stores the parameters in a map, which is not orderable in SalesForce.




Yeah, true... the more I study it, the more I'm sure there is no way to control the order.  Luckily, I talked with IT and it turns out the target system has been upgraded recently and order doesn't matter anymore... so I am saved!


But for anyone who might run into this, I found a decent workaround.  It won't necesarily work for all browser settings (the scripting settings).  It still uses the controller to do the check and to provide the URL string:



<apex:outputPanel rendered="{!myBooleanReturningFunction"> <script type='text/javascript'> top.window.location='{!myURL}'; </script> </apex:outputPanel>