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.
Best Answer
Disregard my ill-informed comment to your OP
ContentNote
is saved with key prefix069
which is aContentDocument
. And,ContentDocument
is the parent ofContentVersion
(key prefix of068
).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 newContentVersion
is created - but under the sameContentDocument
Since
ContentNotes
are typically added as children to some Object (likeAccount
orOpportunity
), the relationship between the ContentNote (i.e.ContentDocument
) and the Account or Opportunity is handled via aContentDocumentLink
.So, what happens first when the Note is first saved?
ContentVersion
is created (trigger possible)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 #1ContentDocumentLink
is inserted - the link(junction) between the Account (or Opportunity or ...) andContentDocument
- trigger also possible