In this article of our Chatter Bot series, Zach Boyd and I wanted a declarative way to take actions when new versions of Chatter Files were uploaded. We had the business requirement to notify a team of people in real-time when updates were occurring.
As standard feature, anyone who follows a Chatter File receives notice in their daily digest of which records or files have been updated, but that notification only occurs once per day and doesn’t include the reason for change when the new file version was uploaded.
At the time of this writing, Process Builder does not support ContentDocument, ContentVersion, or ContentNote objects. The lack of support for these objects makes using Process Builder a bit difficult so we developed Chatter Bot for Files to make this possible.
You can support our cause by voting for the following on the IdeaExchange:
Introducing Chatter Bot for Files
Chatter Bot for Files is a way to easily listen for version changes to Chatter Files and take action. An example would be to automatically notify each user following a File that a new version has been uploaded. This solution, available on GitHub, makes it easy by monitoring for updates on ContentVersion object and then updating a custom object that you can leverage within Process Builder.
Getting Started
- Deploy the code from GitHub
- Assign Chatter Bot Files Admin permission set to your admin user
- Switch to Chatter Bot Files app
- Click on Chatter Bot File tab and click New button. Enter the ID of a Chatter File into the Content Document ID field then click Save button.
- Upload a new version of the file to Salesforce then navigate back to your Chatter Bot File record to see that it has been updated with current version details.
Notify Followers of New File Versions
The solution on GitHub comes bundled with an example Process Builder and Flow that demonstrate how to notify a file’s followers any time a new version is uploaded. The email content is defined by the Chatter Bot File Template email template in the Chatter Bot Email Templates folder.
If you prefer for this not to happen then you can either uncheck the Active checkbox (Chatter_Bot_File__c.Active__c) or deactive/delete the example process/flow.
The process and flow names are, respectively:
- Chatter Bot – Notify Followers of File Change
- Chatter Bot – Notify Followers of File Change Flow
Note that for this specific use case we had to develop some Invocable Apex classes that Flow could run to (1) get list of email addresses of the file’s followers and (2) send email alert with custom options like whether to attach the file to the outgoing email or not.
Excellent! I just forwarded this over to a customer who’s been wanting notifications on files.
LikeLiked by 1 person
Thanks Brian! Hope it works out for them!
LikeLike
Awesome presentation during automation hour!
Do you think it would be possible to use the chatterbotfiles trigger technique to lookup who the file is shared with to change permissions from read only to read/write? Currently you can set contentdocument default sharing based on the parent record, but it defaults to read only so users cannot upload a new version as they could delete/replace with the older attachments.
LikeLiked by 1 person
Thanks for the kind feedback, Kevin. Glad you liked the presentation!
Yes, you can definitely use this solution to modify sharing behavior of the file.
I just did a quick proof of concept in my dev org and I had the Flow do a Fast Lookup on ContentDocumentLink filtered where the ContentDocumentId field equals the Chatter_Bot_File__c.Content_Document_ID__c.
This will give you back a list of one or more records based on who and what all the document is shared with.
You can then do a LOOP over those document links and pass them through a Decision element. The Decision needs to check a couple conditions:
1) That the document link’s ShareType is not already I, and
2) That the document link’s LinkedEntityId equals the entity you want to modify sharing access for.
The second condition is important because like, for example, if the entity is the EmailMessage object then you can’t modify the sharing, you’ll get an error. But if the entity is say an Account then you can change the ShareType from V to I.
How I handled that second condition was check that the ContentDocumentLink.LinkedEntityId starts with 001 (the object key prefix for Accounts). You would do something similar depending on what object(s) you’re supporting.
The caveat is that a ContentDocument by itself doesn’t know it’s parent record so you can’t just say “modify the sharing of the record the file was uploaded to” because that notion doesn’t really exist. ContentDocuments have a related list of entities they are shared to, and they could be shared to multiple users, chatter groups, other objects, etc.
If you wanted to simply grant ALL internal users access to view/edit the files, your Flow might check if a ContentDocumentLink record already exists where the LinkedEntityId equals your company’s main Chatter Group. If no such record exists then do a Record Create to create a ContentDocumentLink linked to the document and shares to your company’s primary Chatter Group. Users in the Chatter Group then inherit whatever sharing access you’ve just created.
LikeLike
Doug, this is great. I’ve been playing around with it to create a the Chatter Bot Files automatically and it seems to be working when I update an existing file but not when I first add the file via Chatter. Is there any way I can get the Chatter Bot File created right when I upload a file via Chatter?
My use case is automatically updating the sharing access to automatically be ‘View’ for all users in the company on specific instances via flows (similar to Kevin Hart’s question).
Thanks man! Hope SE Dreamin’ was a good time.
LikeLiked by 1 person
Hi Wilson,
Thanks for the kind feedback! This “should” be possible, I’ll investigate and follow up. My guess is the trigger needs to fire on ‘insert’ event if it’s not already. Would you mind opening a new github issue?
Thanks!
Doug
LikeLike