[SalesForce] How to create an Account Note or Contact Note via API that is visible in Salesforce UI

I am using the python simple-salesforce library.

Steps to reproduce.

  • Create an Account:
    sf.Account.create({'Name':'Testy Account','AccountNumber':'123456'})
  • Query the Id of your new Account:
    sf.query("SELECT Name,Id FROM Account")
  • Add a note with the parentId:
    sf.Note.create({'ParentId':'0011500001G3OLIXX3','Title':'Sample Note','Body':'This is my test note.'})
  • The note creates successfully and exists if you re-query using the API:
    sf.query("SELECT Title,Body,ParentId from Note")
  • BUT if you are in the Salesforce UI and view the Account object and drill down on the 'Testy Account' there is no note in the Notes section.

Having scoured the web for the better part of a day I can see there is the concept of Content references, something like join's in traditional sql I guess? I'm new to SF API work and am not terribly familiar with all the schema relations.

The basic question is, how do I create a Note, associated to an Account or a Contact that is visible in the SF UI?

Best Answer

You have the 'new' Notes functionality configured. See:

With new Notes, you have to use the ContentNote object, then create a ContentDocumentLink to attach it to the Account. One gotcha is that ContentNote's Content field must be base64 encoded.

I just created a ContentNote from Workbench with this JSON payload - my decoded content is This is a <b>sample</b> note:

{
  "Content" : "VGhpcyBpcyBhIDxiPnNhbXBsZTwvYj4gbm90ZQ==",
  "Title" : "Sample note"
}

Now, to attach it to the Account:

{
  "ContentDocumentId" : "069E0000001uzlNIAQ",
  "LinkedEntityId" : "001E0000002Jv2fIAC",
  "ShareType" : "V"
}

ContentDocumentId is the Id of the ContentNote I just created, LinkedEntityId is the account id, and ShareType (a required field) governs the permissions granted to users - V for Viewer, C for Collaborator, I for Inferred (see the ContentDocumentLink doc for more details). You can also set Visibility to AllUsers, InternalUsers or SharedUsers. For this call, Visibility defaulted to AllUsers, but, again, see the docs for more detail.

And... it worked!

Notes related list

Clicking on the note to see the formatting...

Sample ContentNote

Related Topic