I hope everyone is doing well in this Covid 19 pandemic. We use Files to store large documents in Salesforce. Files have many advantage over attachment which includes large size, ability to share with multiple records etc. and going forward Salesforce is planning to use File instead of Attachment in Lightning.
Developer can create ContentDocumentLink record to Share File With Multiple Records, but Admin don’t prefer the code. So today I have created one Lightning Web Components (LWC) using which we can share file with any supported records.
This is how our output will look like:
I have created Global Action to launch our component as file does not support object specific actions, As LWC are not directly supported in Quick Action so we have used Lightning component as a container. You can check this post to get the idea of how we can use Lightning Web Components with Quick Action.
Here user need to pass record Id to which we need to share file, you will get record id from the URL. Then you need to give share type. We support two types of sharing
- V: Viewer permission. The user can explicitly view but not edit the shared file.
- I: Inferred permission. The user’s permission is determined by the related record. For shares with a library, this is defined by the permissions the user has in that library.
This component is supported on File detail page, if you try to run this component from any other page you will get error message. To go to any file detail, follow these simple steps: Go to File Tab > Select the file and click on down Arrow in last column and select view file detail option and in this screen run this component. As this is Global Action so we use URL parsing to get current file details.
I have also created an unmanaged package, which you can directly install in your org and can do testing or you can use it in your production org as well. Don’t forgot to Add global action in publisher layout.
You can find complete code here as well.
Did you like the post or do you have any questions, let me know in comments. Happy Programming 🙂