12

There seems to be some unusual stuff going on with SObjectType for the enhanced note ContentNote (ERD) object and the underling ContentDocument (ERD) structure.

For example, both these return a single row (with the Id taken from an enhanced note I created);

select Id from ContentDocument where Id = '069R00000002J0m'
select Id from ContentNote where Id = '069R00000002J0m'

and these both return "069":

System.debug(Schema.getGlobalDescribe().get('ContentDocument').getDescribe().getKeyPrefix());
System.debug(Schema.getGlobalDescribe().get('ContentNote').getDescribe().getKeyPrefix());

and this:

System.debug(((Id) '069R00000002J0m').getSObjectType());

outputs ContentDocument.

This turns out to be quite awkward for a change to some existing code that I am making, in that AFAIK the only way to generically identify an enhanced note versus a File attachment is to check that the ContentDocument.FileType has the value "SNOTE". As far as triggers and SObjectType based logic is concerned, ContentDocument is the type.

Please share any insight you may have on what is going on here so that I make my code changes in the cleanest way.

7
  • Did you ever gain any more insight into what is happening here? Trying to put a trigger on ContentDocumentLink that only does something if it is tied to a ContentNote. I would prefer to not do the answer below even though it will work. Mar 4, 2020 at 13:48
  • Hi @JesseMilburn, Sorry at this point this has faded into a blurred (unpleasant) memory...
    – Keith C
    Mar 4, 2020 at 14:30
  • Totally understandable. I'll just query the parents and check for FileType = 'SNOTE'. Thanks for getting back to me. Mar 4, 2020 at 14:32
  • what does 'SNOTE' indicate? Jan 7, 2022 at 18:32
  • 1
    @PartOfTheOhana Likely to be a mime type. Attach a file and then query in the developer console to check the field value. Post a new question if you get stuck.
    – Keith C
    Jan 7, 2022 at 21:05

2 Answers 2

1

ContentDocument contains more fields than ContentNote, ContentDocument will always have LatestPublishedVersionId (As it junction to contentVersion), probably you can use that to your advantage?

if(rec.get('LatestPublishedVersionId')==null){
   //Its a Note
}else{
  //Its content document.
}
1
  • 6
    Thanks Pranay. I think the FileType is probably a better way to go if I have to check fields. Really looking for some explanation of what is going on too.
    – Keith C
    Jul 20, 2018 at 16:04
1

A ContentNote is a ContentDocument with a FileType of "SNOTE".

If you create a ContentVersion record with PathOnClient set to <something>.snote, you'll see that you can query this note through ContentNote as well.

This can be useful if you want to set FirstPublishLocationId when inserting your note, i.e. ContentVersion, to avoid a separate ContentDocumentLink insert, or if you want to add a custom field to your notes, which ContentVersion supports.

(To ensure your note content can be saved, set VersionData to myNoteString.escapeUnicode().escapeHtml4().)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .