displaying files in flow datatable with clickable link
solved an interesting question on ohana slack asking about how to display the files attached to a related record in a “legacy” approval process page.
you can do this using a flow datatable, but there are some tricks required for making a clickable link to the file.
salesforce files have 3 objects, and they dont always play nicely
a) content document : this is the file preview page when you are looking at a file. IDs start with 069
b) content version : these are the file versions, and IDs start with 068
c) content document link these allow the many to many relationship to connect one content document to multiple records. i dont know what the Ids start with …
here are the details on how to build it
to start, you must create an input text variable in your flow named recordId. this will be populated automatically when you add the flow to a record page.
step 1 query the contentDocumentLinks to get any files that are related to the record (LinkedEntityID = recordId)
step 2 use a transform to add the contentDocumentId from each contentDocumentLink to a text collection
step 3 get the contentVersion records where the contentDocumentId is in the text collection, and IsLatest = true (else if people upload multiple versions on a single file, then you will see every version)
step 4 display those contentVersion records in a datatable. select the title column for now, and test it out. then work on the clickable link with the info below
but what about that clickable link? to get this to work, go to object manager, and add a custom formula field to the contentVersion object. call it whatever you want, and use the formula exactly as follows, and add that column to the datatable.
HYPERLINK(“/”&CASESAFEID(ContentDocument.Id), Title )
note the dot in ContentDocument.Id - that took a bit of luck as salesforce has that locked down for unknown reasons:
the insert field wizard does not show the content document field as existing
using the actual api name from the documentation ContentDocumentId throws an error: Field ContentDocumentId does not exist. Check spelling.
but adding the dot gets it to work. This is the second or third time in 15 years of mucking about in the trenches that this has worked in this exact scenario…so if you are in desperate times and salesforce is throwing you some knuckleballs never hurts to try dot id.
the final screen:
and the result of clicking the link:
if you want to embed this flow on a lightning approval process instance page, you will need to tweak it as the recordId variable will be the process instance step, not the Id of the record the files are attached to. Will leave that to you to figure out, hit me on bluesky if you run into issues!
https://bsky.app/profile/goravseth.com