On clicking a button my visualforce page is supposed to redirect to the saveURL defined in my get parameters.

The saveURL is literally just the ID of an object (usually an account), here is the apex:

PageReference contactPage = new PageReference('/' + saveURL);
return contactPage;

It should be "https://na15.salesforce.com/saveURL". But instead it's "https://na15.salesforce.com/https://c.na15.salesforce.com/saleURL". How do I stop this?

  • 2
    It looks like your saveURL value is a fully qualified URL already. Is it not usable as is i.e. just remove the "'/' +"? – Keith C Jun 12 '14 at 12:34
  • I don't understand. This is the URL of the page before: c.na15.visual.force.com/apex/…, as you can see the save URL is not a fully qualified URL it is just an ID. – Adam Jun 12 '14 at 12:36
  • 2
    That looks like a valid Visualforce page URL that should just work passed into the constructor like this new PageReference(saveURL). – Keith C Jun 12 '14 at 12:38
  • Ah I see. Stupid how I had to get rid of the '/' yet it says in the official documentation that having a slash before a partial URL is ok. – Adam Jun 12 '14 at 12:38
  • Your case is a full URL not a partial one. – Keith C Jun 12 '14 at 12:39

As confirmed in the comment thread, the saveURL value was already fully qualified so adding a slash in the code (implying that the URL is relative and so needed converting into a full URL) was the wrong thing to do. So the fix in this case is to just remove the slash prefix:

PageReference contactPage = new PageReference(saveURL);
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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