Declaratively handle when files are shared to records.
This project is inspired by Michelle Hansen who was seeking a way to call a flow when a file is shared to a record.
As of the Summer '19 release, ContentDocumentLink, ContentDocument, and ContentVersion objects are not supported in Process Builder to monitor for record changes. Please vote for Terence Chiu's idea.
Not to be deterred, Michelle and I collaborated to develop an Apex trigger that could know when a file was being shared to a record and then call an autolaunched flow where the business logic could be implemented declaratively.
This project is the result of that awesome collaboration 🙂
Before deploying to production, test in a sandbox or scratch org first. You also may need to update the Apex Test to meet your org's requirements.
If you are unfamiliar with deploying metadata with Visual Studio Code, please complete Quick Start: Visual Studio Code for Salesforce Development before moving forward.
-
Open Visual Studio Code.
-
Clone this repository using the Command Palette.
- Press
Cmd+Shift+P
on macOS orCtrl+Shift+P
on Windows to open the Command Palette. - Enter
clone
then choose the Git: Clone command. - Enter this repository's git url,
https://github.com/douglascayers/sfdx-handle-file-shared-to-record-flow.git
. - Select a folder on your computer where to save this repository's content.
- Press
-
Click Open Repository from the notification that appears.
-
Authorize a Salesforce org using the Command Palette.
- Press
Cmd+Shift+P
on macOS orCtrl+Shift+P
on Windows to open the Command Palette. - Enter
authorize
then choose SFDX: Authorize an Org. - Choose the appropriate login option.
- Enter your desired alias for this org (e.g.
myorg
ormy-sandbox
) - A new browser tab will open. Follow the instructions to log in and authorize the Salesforce CLI.
- Once logged in to your org, return to Visual Studio Code.
- Press
-
Deploy this source to your org.
- In the Explorer side bar, right-click force-app folder then choose SFDX: Deploy Source to Org.
If you are unfamiliar with deploying metadata with Salesforce CLI, please complete Quick Start: Salesforce DX before moving forward.
-
Clone this repository.
git clone https://github.com/douglascayers/sfdx-handle-file-shared-to-record-flow.git
-
Change directory into the project folder.
cd sfdx-handle-file-shared-to-record-flow
-
Deploy metadata to your org, replacing
YOUR_ORG_ALIAS
with an alias you've already authorized with the Salesforce CLI.sfdx force:source:deploy --targetusername YOUR_ORG_ALIAS --sourcepath force-app
-
From Setup, activate the Handle File Shared to Record Flow flow you deployed to your org.
-
Navigate to an account record and add a file to it, either through the Files related list or through a Chatter post.
-
Refresh the page and note that the flow posted a Chatter message, "A file has been shared to this record."
Congratulations, it worked! Now it's time to customize the flow to suit your needs.
-
From Setup, open the Handle File Shared to Record Flow flow.
-
Delete the Post to Chatter action, then add any of your own business logic.
-
Save the flow as a new version then activate the new version.
Go forth and be awesome!