I have a 'document' object in which i have a URL field 'document_URL__c', this URL field have public site and the attachment id. for eg: 'pxx-pxx.cs5.force.com/servlet/servlet.FileDownload?file=attachmentID' Now i want to create a download link to download file on each document object record.

i tried creating a link in visualforce page like below:

<a href="{!Doc.Document_URL__c}" target="_blank" styleClass="btn">Download</a>

but it dint worked for me, as it opens in the new tab with the org url prefix to the {!Doc.Document_URL__c}.

i want the file to be downloaded once you clicked on the link download

can anyone please help me out in this?


I think using URLFOR would make more sense. Try something like this:

<a href="{!URLFOR($Action.Attachment.Download, attachmentId)}" >blah blah</a>
  • I dont have attachmentID here. this function is in a loop (table). i want to directly download the file from the value i have in the URL field – Ritz Arlekar May 10 '17 at 6:44
  • @RitzArlekar It doesn't matter, instead of storing URL in Document_URL__c of attachment, store only attachmentId and populate it accordingly. – Rohit Mourya May 10 '17 at 6:49
  • no i cant do that. client have a requirement of opening the document from the link stored on this URL field – Ritz Arlekar May 10 '17 at 6:56

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.