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
Priyashantha HPPriyashantha HP 

Issue when adding a Note for a Case

I have this request body:

POST /services/data/v37.0/sobjects/Note HTTP/1.1 HOST: ap2.salesforce.com authorization: Bearer [ACCESS_TOKEN] content-type: application/json cookie: BrowserId=wBGf4rC3QK6IdvvndirVSQ content-length: 92
{"Title": "Test case note title", "Body":"Test case note body","ParentId":"5002800000T3Iu0"}

ParentId is a valid Case ID. But I get this as the response:

{
    "message": "Parent ID: id value of incorrect type: 5002800000T3Iu0AAF"
   "errorCode": "FIELD_INTEGRITY_EXCEPTION"
   "fields": [1]
      0:  "ParentId"
}

Not sure what's wrong with the request params. I could successfully add Notes into Contact/Account.

Best Answer chosen by Priyashantha HP
Paradiso SolutionsParadiso Solutions

Note in case is nothing but comments. Note is just filter to comments, if you add a note from ui you will see that it appears in comments. So insert a comment using the following code
    CaseComment newCom = new CaseComment();
    newCom.CommentBody = 'Testing Comment';
    newCom.IsPublished = TRUE;
    newCom.ParentId = '5002800000JLyWZ';

You can add Notes for Contact and Account but not for Case

All Answers

Paradiso SolutionsParadiso Solutions

string pdfcontent = 'attachment';

    Blob k = EncodingUtil.base64Decode(pdfcontent);

    Attachment record = new Attachment(ParentId = '5002800000JLyWZ', Name='Anuja Testing'+'.pdf',  Body = k,ContentType='application/pdf');
    insert record;

Hope this will help you 
Priyashantha HPPriyashantha HP
Thanks for the response.

I need a way of add a Note (https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_note.htm) for a Case but not an attachment.
Paradiso SolutionsParadiso Solutions

Note in case is nothing but comments. Note is just filter to comments, if you add a note from ui you will see that it appears in comments. So insert a comment using the following code
    CaseComment newCom = new CaseComment();
    newCom.CommentBody = 'Testing Comment';
    newCom.IsPublished = TRUE;
    newCom.ParentId = '5002800000JLyWZ';

You can add Notes for Contact and Account but not for Case
This was selected as the best answer
Christopher Pryor 14Christopher Pryor 14
I was reading this article today since I ran into the same issue.  In setup we activated the Notes under Customize > Notes > Notes Settings.
When doing this it enabled the ContentDocument for Attachments and Notes, instead of logging it into the CaseComment as listed above.  

To create a Note from APEX the code below would works:
ContentNote newNote = new ContentNote(Title='Test Note');
insert newNote;
System.Debug('newNote: ' + newNote);

ContentDocumentLink newLink = new ContentDocumentLink(LinkedEntityId='CASEID' , ContentDocumentId=newNote.Id, ShareType='V');
insert newLink;
System.Debug('newLink: ' + newLink);


I attempted to do it used the Note object directly, but for Cases you get an error:System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Parent ID: id value of incorrect type: CASEID: [ParentId]

I am using the code above to get test execution on a trigger for the ContentDocumentLink object for when a note is put in the system it should update other items in the system.