0

How do I add notes and attachments to opportunity objects via SObject Tree. I am dong this via java script ajax POST "New Notes" "Attach File"

"Opportunities": {
 "records": [{
   "attributes": { "type": "Opportunity", "referenceId": "opp1" },
   "name": "Closing Soon",
   "closedate": "2018-09-01",
   "stagename": "Prospecting"
 }]
0

Create a Note or Attachment simply by providing them as children records of the parent record; reference the relationship name Notes or Attachments to insert the appropriate type of record.

Example:

{
 "records": [{
   "attributes": { "type": "Opportunity", "referenceId": "opp1" },
   "name": "Closing Soon",
   "closedate": "2018-09-01",
   "stagename": "Prospecting",
     "Notes": { "records": [{
       "attributes": { "type": "Note", "referenceId": "note1" },
       "title": "This is a note",
       "body": "This is the content of the note"
     }]},
     "Attachments": { "records": [{
       "attributes": { "type": "Attachment", "referenceId": "att1" },
       "name": "filename.txt",
       "body": "VGhpcyBpcyB0aGUgY29udGVudCBvZiB0aGUgYXR0YWNobWVudA==",
       "contenttype": "text/plain"
     }]}
 }]
}

Please note that the body of an attachment must be base64-encoded.

  • so if the user browse a file from their computer image, or pdf, it has to change to base64 first , and then pass that to the body – Metawaa Mar 9 '18 at 19:58
  • @Metawaa Yes. You can use FileReader.readAsDataURL to convert the file to base64, then upload the body part. – sfdcfox Mar 9 '18 at 20:03
  • do I need to have the extension for the file in conteentType? like if is PDF or JPEG? – Metawaa Mar 9 '18 at 20:08
  • 1
    @Metawaa Use the content type that the browser gives you from the data URI. It should be a mime type, like "image/jpeg" or "application/pdf". – sfdcfox Mar 9 '18 at 20:16
  • how do you make it so if attachment is empty, still submits the sobject tree. right now when its empty , it errors out – Metawaa Mar 12 '18 at 17:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.