2

Is it possible to manipulate note sharing settings in a trigger? (after insert) I wanted to set a default specific set of users whenever a new note is created. I've tried searching everywhere to no avail. I'm talking about the New Notes Tool SFDC released, not the "Notes and Attachments" one.

Thank you in advance!

2

The sharing for the new Notes tool (API-name ContentNote) is arranged in the same way as for the already existing Salesforce Files functionality.

The datamodel looks like this: https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_erd_contentnote.htm

As you can see, the sharing is managed via the ContentDocumentLink object. You can delete existing sharing or add new ones using triggers.

The documentation for writing triggers on that object is also in the Winter '16 release notes: https://releasenotes.docs.salesforce.com/en-us/winter16/release-notes/rn_chatter_files_content_triggers.htm

|improve this answer|||||
  • I see that content document links whatever the parent record is for the notes, but what I don't see is what field am I going to use in the content document link object, there seems to be no field for adding/ deleting existing sharing. Could you please enlighten a bit more? A short snippet would really be great. I'm a bit new (just finished Trailhead's beginner developer trail) that I am not even familiar with manipulating the SFDC's files. Thanks again! – Julienn Sep 26 '16 at 14:58
  • You can create multiple ContentDocumentLink records for 1 ContentDocumentId. So if you need a add a sharing, create an additional ContentDocumentLink for that ContentDocumentId. Also you can delete existing ContentDocumentLink records. – Guy Clairbois Sep 26 '16 at 15:17
  • As an example you could use the 'publishConentToAnotherLibrary' example shown in my last link to the release notes. That code creates a new ContentDocumentLink. – Guy Clairbois Sep 26 '16 at 15:24
  • Oh now I get it, for each ContentDocumentLink, it corresponds to one sharing setting having the ContentDocumentId as the ContentNote being shared, and the LinkedEntityId as the Id of the user having a sharing setting with the ContentNote. Should've understood that with the ERD you gave, but oh well.. Thanks Guy! Your answer is spot on, just had a problem with me understanding it lol – Julienn Sep 26 '16 at 15:30
  • No problem, glad to be of help :-) – Guy Clairbois Sep 26 '16 at 15:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.