4

I have seen that developers use 2 different formulas for the users to download a file/attachment.

1st -

HYPERLINK("servlet/servlet.FileDownload?file=" + recordId , 
          Name + "<valid extension>","_blank")`

2nd -

HYPERLINK("sfc/servlet.shepherd/version/download/" + recordId +
         "?asPdf=false&operationContext=CHATTER", 
         Name + "<valid extension>","_blank")

Can someone please explain when to use which formula? Which recordID we are exactly passing on here?

1 Answer 1

4

The former ("servlet.FileDownload") is used for classic Attachment and Document records, while the latter is for ContentVersion records (e.g. as uploaded to Chatter or Salesforce Files). You use the first one to link to a file in classic storage, and the second to link to the newer file storage. In the first link, the record ID is the Document/Attachment's ID, and in the second, it's the ContentVersion ID.

2
  • Thanks Brian, so the URL parameter operationContext is CHATTER all the time for Salesforce files ?
    – Jarvis
    Commented Sep 13, 2018 at 15:52
  • @Bennie I don't think it's necessary; someone most likely copied a literal URL from chatter and used it in the formula. You can experiment with it to see.
    – sfdcfox
    Commented Sep 13, 2018 at 16:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .