1

When you create a new enhanced Note in the UI, it creates a ContentNote and a ContentDocument record. Does anyone know the creation order of the records? Client wants me to write a trigger for the enhanced Note, and triggers are allowed only for ContentDocument, not ContentNote.

  • ContentNote is related to ContentDocument via ContentDocumentLink (a junction). Triggers are available on ContentDocumentLink which will only exist once both of its parents exist (ContentNote, ContentDocumentLink) – cropredy Aug 18 '16 at 14:41
  • Yes, but what is the order of creation? Is the ContentNote created first or the ContentDocument? – David Cheng Aug 18 '16 at 18:46
  • why does it matter; until the ContentDocumentLink is inserted, you don't have a trigger point to attach code to; and by then, you have access to both the ContentNote and ContentDocument to do what you need to – cropredy Aug 18 '16 at 19:38
4

Disregard my ill-informed comment to your OP

ContentNote is saved with key prefix 069 which is a ContentDocument. And, ContentDocument is the parent of ContentVersion (key prefix of 068).

You can think of the ContentDocument as the header and ContentVersion as the actual "note" -- with multiple versions supported. As you edit the Note and click Save, a new ContentVersion is created - but under the same ContentDocument

Since ContentNotes are typically added as children to some Object (like Account or Opportunity), the relationship between the ContentNote (i.e. ContentDocument) and the Account or Opportunity is handled via a ContentDocumentLink.

So, what happens first when the Note is first saved?

  1. ContentVersion is created (trigger possible)
  2. ContentDocument is created (happens automatically when the first ContentVersion is saved). Trigger is also possible although it is not clear to me if you'll get control when this object is initially inserted via the side effect of #1
  3. ContentDocumentLink is inserted - the link(junction) between the Account (or Opportunity or ...) and ContentDocument - trigger also possible
3

FYI to anyone else struggling with this as I am, this is the trigger firing order when the "New" Content Note button is clicked:

ContentVersion BEFORE_INSERT
ContentDocument BEFORE_INSERT
ContentDocument AFTER_INSERT
ContentDocumentLink BEFORE_INSERT
ContentDocumentLink AFTER_INSERT
ContentDocument BEFORE_UPDATE
ContentDocument AFTER_UPDATE
ContentVersion AFTER_INSERT
ContentDocumentLink BEFORE_INSERT
ContentVersion BEFORE_UPDATE
ContentDocument BEFORE_UPDATE
ContentDocument AFTER_UPDATE
ContentVersion AFTER_UPDATE
ContentDocumentLink AFTER_INSERT

and when "Save" is clicked:

ContentVersion BEFORE_INSERT
ContentDocument BEFORE_UPDATE
ContentDocument AFTER_UPDATE
ContentVersion AFTER_INSERT

PS

Just found this detailed post Triggers on ContentObjects.

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.