9

I'm doing an integration that involves passing fully qualified URLs to another application as form inputs so that they can be used for a callback. The URL is for another Visualforce page (not a webservice). For example, a form might look something like this:

<form action="https://myformaction">
    <input type="hidden" name="callbackUrl" value="URL-GOES-HERE"/>
    <!-- rest of the form -->
</form>

I'm having trouble getting a valid, fully qualified URL to show up. Here's what I've tried:

  1. {!URLFOR($Page.PageName)} ==> /siteprefix/PageName, which doesn't work because it's a relative URL, so the external service can't redirect to it.

  2. {!$Site.CurrentSiteUrl}{!URLFOR($Page.PageName)} ==> https://salesforce.domain/siteprefix//siteprefix/PageName, which doesn't work because the siteprefix is included twice, and there's a double //

  3. https://{!$Site.Domain}{!URLFOR($Page.PageName)} ==> https://salesforce.domain/siteprefix/PageName, which works for now - but I'm worried it will break when we switch to a custom domain down the line.

I've run into the same problem when trying to include links in Visualforce email templates, where the $Site variable isn't available. Am I missing something? Seems like this should be a simple thing to do...

6

I just heard from someone at Salesforce that for Visualforce pages, this solution should work even with custom domains:

https://{!$Site.Domain}{!URLFOR($Page.PageName)}

However, that doesn't solve the problem for email templates.

2

I've been using URL.getCurrentRequestUrl() (as documented in http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_url.htm) then using String manipulation to build the URL that I want and exposing that through a Custom Controller/Controller Extension for similar functionality.

The issues with this are:

  • doesn't work with @future annotated methods (I need to query for the Site that I'm operating in)
  • won't work for your email case.

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.