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
SkiesnPiesSkiesnPies 

Strange Problem with PageReference Constructor and Lost Parameters (divert)

Have a strange problem stopping a go live today :

 

Am creating a page reference in order to diver to an external site. 

 

The URL I am diverting to (not real) is : 

https://mydomain.redirect.php?obcdefghijklmn

 

so I have

 

String mystring = 'https://mydomain.redirect.php?obcdefghijklmn';

and then

PageReference redirectPage = new PageReference(mystring);

redirectPage.setRedirect(true);

return redirectPage;

 

however what I end up with in my divert is : 

https://mydomain.redirect.php

 

 

and if change my code to do this : 

PageReference redirectPage = new PageReference(mystring);

system.debug('StoredURL=' + redirectPage.getURL());

redirectPage.setRedirect(true);

return redirectPage;

 

the debugger shows the same 

https://mydomain.redirect.php

 

ie. it has lost all the parameters?????

 

What I did find is that Apex doesn't do this if the URL is 

https://mydomain.redirect.php?MYPARAM=obcdefghijklmn;

 

But it seems rather unfair that SFDC is making decisions about what is a valid URL and what isn't - as the PHP URL's all get broken (I can't control what URL's I will get as they come from an API call out). 

 

Any suggestions? I know I could return the string to my VF page and divert using JS but for security reasons (don't ask) I can't do this.....

 

 

Tim BarsottiTim Barsotti

I am pretty sure that SFDC requires all parameters be in KEY=Value format. 

 

Such as, redirectPage.getParameters.put('MYPARAM', 'obcdefghijklmn');

 

Thus rendering in the format http://myurl.com?MYPARAM=obcdefghijklmn

 

Can your PHP server take Key / Value parameters? 

SkiesnPiesSkiesnPies

I feared this would be the case, its kind of frustrating really very very frustrating that SFDC has decided that it will be the Lord and Master of all other server URL rules - if some other server protocol allows non pair URL parameters who are SFDC to say you can't link to it? 

 

Its fair enough stipulating the formatting and the pair relationship on an internal parameter or URL, but on external re-directs? Essentially it means you can't externally re-direct to a PHP page?????

 

As I am receiving URL's from potentially any service, I need to be able to pass this on as it is without SFDC "helping me out". 

 

Very unwelcome I have to say. 

 

Tim BarsottiTim Barsotti

I recommend you create an Idea on the ideas exchange for SFDC to create a product enhancement. 

SkiesnPiesSkiesnPies