function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Oscar OmanaOscar Omana 

Created Note not showing on related object

I'm using rest api to create a note, it goes like this:
 {
    "Title":"note title ",
    "ParentId":"00Q46000004UQ9YEAW",
    "Body":"note body bhugvyf"
}

The parent is a Lead, but that note wont show on the Notes of that lead. The only notes that appear are the ones directly created on the browser.
Any idea on how to address this issue? 
Thanks
Debanjan SharmaDebanjan Sharma
Hi Oscar,

You have to add ContentDocumentLink to attach it to related object.

Request payload should look like-
 
{
  "ContentDocumentId" : "<Content Id>",
  "LinkedEntityId" : "<Related Object Id>",
  "ShareType" : "V"
}
ShareType is a required field, used to grant permission to the user. V for view, C for Collaborator, I for Inferred. You can refer the official documentation for more details (https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_contentdocumentlink.htm).

Regards,
Debanjan
Oscar OmanaOscar Omana
Thanks Debanjan, I've tried what you said but it gives me an FIELD_INTEGRITY_EXCEPTION. It says "a link cant be created for this type of entity through the api"
Debanjan SharmaDebanjan Sharma
Hi Oscar,

I realized you are hitting the "/services/data/v41.0/sobjects/Attachment/" endpoint to insert the Note.

Insetead of this you can create a Note using "/services/data/v41.0/sobjects/ContentNote/".
The request payload should be like-
{
  "Content" : "<Blob Value of Body>",
  "Title" : "Sample note"
}

Then you can link it with a related object by inserting a ContentDocumentLink.
Endpoint- "/services/data/v41.0/sobjects/ContentDocumentLink"
The request payload should be ike-
{
  "ContentDocumentId" : "<Content Id>",
  "LinkedEntityId" : "<Related Object Id>",
  "ShareType" : "V"
}

Regards,
Debanjan