Winter ’14: outputLink automatically adding Site prefix?

We just noticed an issue today with some links we had on our Force.com site where some links to download some PDFs (stored as Documents in SF) were broken in our test environment (Winter ’14) but not on production (still Summer ’13)

The code looks something like this:

<apex:outputLink value="/mySite/servlet/servlet.FileDownload?file={!consentFormId}&oid={!$Organization.Id}"
styleClass="standard-blue-button" target="_blank">
{!$Label.lnk_PrintConsentForm}
</apex:outputLink>

In production, the link is fine, but in our staging environments, it seems like Winter ’14 is automatically adding in the site prefix, even though I didn’t ask it to, so I end up with /mySite/mySite/servlet/….

Anybody else experiencing this?

PS – didn’t find anything in the release notes related to outputLink or site prefix.

EDIT: clarification on this….the original bug that raised this issue for us was that we have two separate sites that use the same code base, and the hard coded “/mySite/” url was working fine for the one site, but for the other, Salesforce was throwing in “/mySite2/mySite/…” This behaviour was seen in both environments, so it wasn’t a Winter ’14/Summer ’13 issue, but rather it worked in one site but not the other because of the hard coding.

The issue is that SF appears to be parsing the outputLink’s value attribute and massaging it if it thinks there’s an error in there, like not having the right site prefix, so it throws it in there for you. Appears to be an undocumented feature for outputLink.

This can be avoided all together by using the solution in the answer below. (at least for my particular scenario, see comments)

Answer

Try the following change:

<apex:outputLink value="{!URLFOR($Action.Document.Download,consentFormId,[file=consentFormId,oid=$Organization.id])}" styleClass="standard-blue-button" target="_blank">
{!$Label.lnk_PrintConsentForm}
</apex:outputLink>

This should construct the correct URL in all cases (including internal pages, etc).

Attribution
Source : Link , Question Author : Stephen , Answer Author : sfdcfox

Leave a Comment