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

PageReference with EncodingUtil.urlEncode - possible bug

I suspect this may be a bug but someone please tell me otherwise if it's not. I've just been pulling my hair out for the last few hours...


I have the following piece of code for example:

public PageReference PageInit(){
PageReference result = new PageReference('/apex/MyVisualforcePage');
result.getParameters().put('subject', EncodingUtil.urlEncode('Hi how\'s it going....', 'UTF-8'));
return result

 When the method was called it returned the following url:

Which was obviously causing problems. The text ending up looking like this "Hi+how%27s+it+going...." in my visualforce page textbox.


But an earlier page I had written a few months back, given the save parameter value was returning the following url:'s+it+going....


I finally found the reason, my new visualforce page had an API Version of 19.0, whereas the earlier page was at 16.0. I changed my new page to API Version 18.0 and all is working fine now.


The encoded parameter value becomes corrupted, by the way, when the PageReference getUrl() is called. EncodingUtil.urlEncode() seems to be functioning normally.


Any similiar problems, comments, or explanations are welcome. It would be good to find out what's going on here.