How can I 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?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x