1

This question already has an answer here:

the url that I'm putting into the pagereference constructor isn't the one that's popping out. it's stripping off the last &retURL that's part of my &save_new_URL.

what's going on and how do i fix it?

code:

String url = '/setup/ui/recordtypeselect.jsp?ent=Task';
url+= '&retURL=/' + this.who_Id; 
url+='&save_new_URL=/apex/taskOverRide?who_id=' + this.who_Id + '&retURL=/' +this.who_id ;
system.debug('URL: ' + url);
PageReference p = new Pagereference(url);
system.debug('URL: ' + p.getUrl());
p.setRedirect(true);
return p;

string URL output:

URL: /setup/ui/recordtypeselect.jsp?ent=Task&retURL=/003e0000004owon&save_new_URL=/apex/taskOverRide?who_id=003e0000004owon&retURL=/003e0000004owon

output from the constructor

 /setup/ui/recordtypeselect.jsp?ent=Task&retURL=%2F003e0000004owon&save_new_URL=%2Fapex%taskOverRide%3Fwho_id%3D003e0000004owon

marked as duplicate by eyescream, Mike Chale, Sergej Utko, Samuel De Rycke, Matt Lacey Jun 6 '13 at 23:56

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

You are calling the parameter retUrl twice, and I think pageReference notices that and only uses one of the retUrls.

When you add the parameters to the URL, certain characters are encoded. Check out this resource: http://en.wikipedia.org/wiki/Percent-encoding

Try encoding the second retUrl yourself, and then it shouldn't be confused and parsed out.

string saveUrl='&save_new_URL=/apex/taskOverRide?who_id=' + this.who_Id + '&retURL=/' +this.who_id ;
//encode the URL
saveUrl=saveUrl.replace('&','%26').repalce('=','%3D').replace('/','%2F'); //.replace(otherNecessaryCharacters,accordingly)

url+=saveUrl;
  • 2
    Why not just use EncodingUtil.urlEncode and EncodingUtil.urlDecode? salesforce.com/us/developer/docs/apexcode/Content/… – drakored Jun 6 '13 at 19:18
  • saveUrl = EncodingUtil.urlEncode(saveUrl,'UTF-8'); url += saveUrl – drakored Jun 6 '13 at 19:19
  • 1
    Yup, that'll do it all too in one step. And it's nice to know what's actually being encoded. That's a useful class for converting to Base64 and back! – Scott Pelak Jun 6 '13 at 20:58

Not the answer you're looking for? Browse other questions tagged or ask your own question.