2

So I've created a custom object and added the Notes to available related lists on the page layout. Now I want to manage notes through the REST API.

enter image description here

The problem is, I have no idea how to access the notes. I found a suggestion that AttachedContentNote is a wrapper around ContentNote, and that seems to be supported by the fact that I can see my note under services/data/v43.0/sobjects/ContentNote/listviews/00B2v00000Osr6REAR/results, but that doesn't link it to the custom object records, which is what I assume AttachedContentNote does.

The problem is that I can't seem to find the AttachedContentNote object. I've looked at AttachedContentNote docs and it indicates that there is a LinkedEntityId field, but using this in a query (e.g. services/data/v43.0/sobjects/AttachedContentNote/LinkedEntityId/00B2v00000Osr6R) tells me that the field doesn't exist or isn't accessible (the access token belongs to the system administrator user, so I assume it doesn't exist).

On further reading, I've noticed that the documentation for AttachedContentNode states the following, which doesn't clear up how to actually access the notes:

To retrieve ContentNote objects, issue a describe call on an object, which returns a query result for each note created or attached. You can’t directly query this object.

How do I list and access notes belonging to a given entity? If I have custom object id X, how do I find, create, and update, etc. content note Y using REST?

4
  • The notes are simply a ContentDocument with FileType as SNOTE. So you can use SOQL against ContentDocumentLink with related query to ContentDocument fields.
    – zaitsman
    Commented Jan 31, 2020 at 3:52
  • @zaitsman is SOQL the only way? No REST endpoint without a query? Commented Jan 31, 2020 at 4:03
  • Soql can be run through rest? I don’t know about other endpoints, i use soql for everything, all objects :)
    – zaitsman
    Commented Jan 31, 2020 at 4:09
  • @zaitsman I see. Thank you. Commented Jan 31, 2020 at 4:16

2 Answers 2

2

AttachedContentNote does not support query operation.

To find related notes for an object:

Execute a query on ContentDocumentLink through REST GET call as follows to retrieve ContentDocument of type 'SNOTE' for your custom object

https://yourInstance.salesforce.com/services/data/v47.0/query/?q=SELECT+id,ContentDocument.Title,+ContentDocumentId+FROM+ContentDocumentLink+where+LinkedEntityId+in+(+SELECT+Id+FROM+YourCustomObject__c)+and+ContentDocument.FileType+=+'SNOTE'

Replace YourCustomObject__c by your custom object API name.

It is recommended to filter further the inner query SELECT Id FROM YourCustomObject__c so that you do not exceed limits.

To create ContentNote object via REST API

For example perform a POST call to https://yourInstance.salesforce.com/services/data/v47.0/sobjects/ContentNote

Add relevant fields in the request body

{
"Title" : "Your note",
"FileType" : "SNOTE", ....
}

Note that Content field in ContentNote must be in base64.

When a ContentNote is created, a ContentDocumentLink record is automatically created to link the note with the user performing the operation.

To link it to another record, create another ContentDocumentLink record via a POST request

https://yourInstance.salesforce.com/services/data/v47.0/sobjects/ContentDocumentLink

{
"ContentDocumentId" :"0691t00000WoZc8AAF",
"LinkedEntityId" : "a001t00000GQdDdAAL", 
"ShareType" : "I"
}

where ContentDocumentId matches the id returned after creating ContentNote, LinkedEntityId matches your custom object record, ShareType determines the sharing access, refer to the documentation for more details about possible values

References

ContentNote
ContentDocumentLink
ContentDocument
Create record using REST API
Update record via REST API

3
  • If I create a ContentNote via REST, how do I associate it with YourCustomObject__c? Commented Jan 31, 2020 at 8:00
  • 1
    @John you need to perform another create operation to insert a ContentDocumentLink and associate it with your custom object record id. I've edited the last section of the answer to provide more details about this
    – Shamina
    Commented Jan 31, 2020 at 8:15
  • 1
    I see. Makes sense. Thanks Shamina! :-) Commented Jan 31, 2020 at 8:17
0

Adding to already accepted answer:

using composite request, below is payload:

uri: /services/data/v50.0/composite method: POST payload:

{
    "allOrNone" : true,
    "compositeRequest": [{
        "method": "POST",
        "url": "/services/data/v50.0/sobjects/Case",
        "referenceId": "newCase",
        "body": {
            "RecordTypeId":"0120W000001pOoDQAU",
            "Type": "Vending Repair"
        }
    },{
        "method" : "POST",
        "url" : "/services/data/v50.0/sobjects/ContentNote",
        "referenceId" : "newNote",
        "body" : {
            "Title" : "Harrison-Title",
            "Content" : "SGFycmlzb24tQm9keQ=="
        }
    },{
        "method" : "POST",
        "url" : "/services/data/v50.0/sobjects/ContentDocumentLink",
        "referenceId" : "newCDL",
        "body" : {
            "LinkedEntityId" : "@{newCase.id}",
            "ContentDocumentId" : "@{newNote.id}"
        }
    }]
}

You must log in to answer this question.

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