How I Solved It: File Deletion Flow
Working with Salesforce Files can be complicated, especially when it comes to deleting files that others have uploaded. The article addresses the pain point where users often lack the permission to delete files they didn't upload, and system admins have to handle deletions manually. It demonstrates a declarative screen flow solution that lists files related to a record, allows a user to select one for deletion, and deletes the actual file while running with system permissions to bypass ownership issues. The flow is designed to be object-agnostic and reusable across different Salesforce objects, offering an elegant approach to managing file deletions without granting broad admin permissions to users.
- Use a screen flow to list ContentDocumentLinks for a record and allow file deletion.
- Run flows in system context without sharing to bypass ownership restrictions.
- Delete ContentDocument directly to remove the file and all links cleanly.
- Build object-agnostic flows by accepting record Id as a variable input.
- Avoid SOQL queries inside loops by leveraging record variable assignments.
I know I'm not the only one that thinks it's a pain to work with Files in Salesforce. Stories of frustration, confusion, and downright bafflement abound. The object structure for what seems like a relatively simple and convenient File uploader on the page layout is anything but simple under the hood. ContentDocument , ContentDocumentLink, ContentVersion, ContentHistory, ownership, permissions, ... The list of considerations just keeps going. I could probably try to write a post explaining it in simpler terms but, frankly, I don't think I really understand it, so I would probably just lead you astray in some way. But I recently built something that turns out to be surprisingly simple and solves a common problem with Files, so I'm going to share that with you instead. The Business Problem Lots of organizations use Files in Salesforce, usually in the ways you would pretty much expect.