The Art of URL Hacking in Salesforce : Part IV— File Preview & Downloads

Shivam Vishwakarma
5 min readDec 17, 2023

--

In my previous article I had explained how one can use Salesforce URL Hacks to open Global & Object Specific Quick Actions.

If you haven’t read that yet, I would really encourage you to take the time to read once.

In this Article, I’ll explain how you can use URL Hacks to Preview & Download Files.

For those of you, who are new to Salesforce File Management, here’s a bit of additional information.

Salesforce currently (As of Winter’24 Release) supports two ways of uploading & maintaining Documents/Files/Attachments in the Org.

Document Object was initially introduced with Classic version of Salesforce and was available for use in VF pages, Email Templates etc.
Even today, if you want to access files present in Document Object, you’ll have to switch to Salesforce Classic and then you’ll be able to see Documents Tab after clicking “+” Icon, to view all Tabs.

With introduction of Lightning Experience, Salesforce has moved to the newer ContentDocument & ContentVersion (Versioning of File) objects to maintain the Files in Org.

There are few Awesome articles by Katie Conway on the DriveConnect Website, which explains in depth the Salesforce Files Architecture & how you can leverage it in Apex & UI [Aura/LWC/VF].

A] Preview & Download Files stored in ContentDocument / ContentVersion Objects using URL Hack

I. Preview the File :

You can only Preview Files of the ContentDocument Object (i.e. The Latest version of the File)

/lightning/page/filePreview?selectedRecordId=<ContentDocumentRecordId>

E.g. Previewing an Image stored as a File in ContentDocument object with Id as 0692x00000AGamyAAD

/lightning/page/filePreview?selectedRecordId=0692x00000AGamyAAD
File Preview, stored in ContentDocument object

II. Download the File :

You can Download both Latest version of a File, i.e. a ContentDocument , or a specific version of the File, i.e. a ContentVersion using url hacks.

a. ContentDocument:

/sfc/servlet.shepherd/document/download/<ContentDocumentRecordId>

E.g. Downloading an Image stored as a File in ContentDocument object with Id as 0692x00000AGamyAAD

/sfc/servlet.shepherd/document/download/0692x00000AGamyAAD

b. ContentVersion:

/sfc/servlet.shepherd/version/download/<ContentVersionRecordId>

E.g. Downloading an Image stored as a File in ContentDocument object with Id as 0692x00000AGamyAAD, having a historic file version with ContentVersion Id as 0682x00000APecGAAT. [You’ll have to Query this to find the specific versionIds]

/sfc/servlet.shepherd/version/download/0682x00000APecGAAT

Some Additional Information :
When you are downloading Files from Salesforce Chatter / Files Tab / other locations, you will notice an additional url parameter “operationContext”.
This parameter can have the following values : CONTENT, CHATTER, DELIVERY, S1, or MOBILE. These are in fact the “ContentDownloadContext ENUMs that specifies the download context.

III. Downloading & Previewing the Thumbnail of an Image uploaded as a File — i.e RenditionDownload

Currently supported by only ContentVersion object (For both Latest & Historical ContentVersion records)

/sfc/servlet.shepherd/version/renditionDownload?rendition=THUMB720BY480&versionId=<ContentVersionRecordId>

Following Thumbnail sizes are available for “rendition” attribute:

  • THUMB120BY90,
  • THUMB240BY180,
  • THUMB720BY480

E.g. Downloading & Previewing the Thumbnail of an Image with dimensions of 720x480.

/sfc/servlet.shepherd/version/renditionDownload?rendition=THUMB720BY480&versionId=0682x00000APecGAAT

IV. Downloading multiple Files as Zip

a. Via ContentDocument Ids

In-order to download multiple Files together as Zip, you can use the following URL, with multiple ContentDocument Ids separated by “/ “ (i.e. forward-slash) and ending with a “?”

/sfc/servlet.shepherd/document/download/<ContentDocumentRecord1_Id>/<ContentDocumentRecord2_Id>?

b. Via ContentVersion Ids

In-order to download multiple Files together as Zip, you can use the following URL, with multiple ContentVersion Ids separated by “/ “ (i.e. forward-slash) and ending with a “?”

/sfc/servlet.shepherd/version/download/<ContentVersionRecord1_Id>/<ContentVersionRecord2_Id>?

E.g. Downloading 3 Files in a Single Zip.

a. ContentVersion Ids as 0682x000008pi2dAAA, 0682x00000APecGAAT, 0682x000009ktZIAAY

/sfc/servlet.shepherd/version/download/0682x000008pi2dAAA/0682x00000APecGAAT/0682x000009ktZIAAY?

b. ContentDocument Ids as 0692x00000AGamyAAD, 0692x000008cWOrAAM, 0692x000009PHesAAG

/sfc/servlet.shepherd/document/download/0692x00000AGamyAAD/0692x000008cWOrAAM/0692x000009PHesAAG?

The below mentioned article mentions that the above-approach supports multiple files download as Single Zip with File size > 400MB.

B] Preview & Download Files stored in Document Object using URL Hack

Preview / Download the File :

You can use the following URL Hack to directly download/preview (if preview is allowed for the file) stored as a Document object.

/servlet/servlet.FileDownload?file=<DocumentId>

E.g. Previewing & Downloading a Document File with Id as 0152x000001OAQd

A File stored in Document Object
/servlet/servlet.FileDownload?file=0152x000001OAQd
File Preview using the above mentioned URL

I hope you enjoyed this article 📖 & found it insightful! 🔍!
Do hit the clap button👏 if you liked the article & leave a comment✍ if you have any queries/suggestions.

Enjoying the content? Don’t miss out on my future posts! Hit ‘Follow’ button to be the first to know about my new publications 🔔. Can’t wait to share more! 🚀🎉

Thanks for reading!

--

--

Shivam Vishwakarma

I'm a Salesforce Developer & CRM Analytics Enthusiast! Visit my LinkedIn to know more about me : linkedin.com/in/shivamashokvishwakarma