5

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?

4
  • Nothing terribly wrong with your flow. It should be working as advertised; everything looks okay. Perhaps you're looking at the wrong related list?
    – sfdcfox
    Commented Jan 7, 2016 at 1:17
  • Are you using the same username/password with Python and the browser? Can you see it if you put the Note Id (returned by the create call) on the end of the URL in the browser - e.g. na1.salesforce.com/002E000000AEoWz ? I just tried the same thing from the Workbench and it works just fine - it shows up in 'Notes & Attachments' exactly as I would expect.
    – metadaddy
    Commented Jan 7, 2016 at 4:05
  • @metadaddy, that's surprising. I am using Sales Cloud, Lightning Experience interface. There is no "Notes & Attachements" tab. There is "Account" and there is a "Notes" sub item within that view. Are you using the same? Commented Jan 7, 2016 at 13:24
  • I'm using Sales Cloud in a Developer Edition, Lightning Experience. I scroll to the bottom of the Account's related lists and there it is: imgur.com/81bVnWN
    – metadaddy
    Commented Jan 7, 2016 at 17:49

1 Answer 1

9

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

6
  • 3
    That was perfect. I owe you several days of my life for that answer. Commented Jan 7, 2016 at 22:49
  • 1
    One more note, for anyone else using the simple-salesforce utility. Be sure to change the api version in api.py to the actual most recent SF api version. The git version is on 29.0 and it seems the ContentNote object was introduced sometime after v29. I used v34 and it worked just as @metadaddy detailed. Commented Jan 7, 2016 at 22:51
  • You can pay me back by asking and answering more questions here ;-)
    – metadaddy
    Commented Jan 8, 2016 at 6:28
  • maybe this belongs in another thread but is there a way to make the ContentNote and ContentDocumentLink creation atomic? For scripting, it's not easy to associate the newly created ContentNote, then re-query to hopefully match and find the correct Id SF assigned to that note, then create the ContentDocumentLink with that Id. Commented Jan 8, 2016 at 21:52
  • 1
    Nevermind, the Create command returns the id. Duh. Commented Jan 8, 2016 at 22:00

You must log in to answer this question.

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