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 is the full flow.

Screenshot from 2025-05-02 12-20-28.png

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)

Screenshot from 2025-05-02 12-38-58.png

step 2 use a transform to add the contentDocumentId from each contentDocumentLink to a text collection

Screenshot from 2025-05-02 12-41-59.png

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)

Screenshot from 2025-05-02 12-43-24.png

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

Screenshot from 2025-05-02 12-44-16.png

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

Screenshot from 2025-05-02 12-25-58.png

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:

Screenshot from 2025-05-02 12-48-35.png

and the result of clicking the link:
Screenshot from 2025-05-02 12-49-43.png

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

 
0
Kudos
 
0
Kudos

Now read this

scheduled flow + vf email template demo

I have built out a demo scheduled flow that sends an email to each opportunity owner with a list of open opportunities, using a visualforce email template. This flow is much like a report subscription, but with more context, and without... Continue →