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
Brandon Bridges 16Brandon Bridges 16 

How can I create a note programmatically and attach it to a case? (note: parentid cannot be a case object)

I've tried a few different ways. the hard coding is just for testing...
List<note>mylist=new List<note>();
NOTE thisNote = new NOTE(body='hey!',title='noteB');
case mycase=[SELECT id,accountid,ownerid from case where id=:'500P0000005bZv1IAE' LIMIT 1];

thisNote.OwnerId=mycase.ownerid;
thisNote.isPrivate=false;
thisNote.parentId=mycase.accountid;
           myList.add(thisNote);
insert(mYList);*/

    
attachment attach=new attachment();
attach.name='testme';
attach.body=Blob.valueOf('informationg oes hesoejh');
attach.parentID='500P0000005bZv1';
insert attach;*/


task mtask=new task();
mtask.description=('yolo');
mtask.whatid='500P0000005bZv1';
mtask.subject='subjectB';
mtask.ownerid=UserInfo.getUserID();
mtask.status='Open';

caseComment newComment = new CaseComment();
newComment.CommentBody='hello';
newComment.IsPublished=TRUE;
newcomment.ParentId='500P0000005bZv1';
    
upsert newComment;
System.Debug(newComment.id);*/


contentnote Cnote=new contentnote();
Cnote.content=Blob.ValueOf('contentB');
Cnote.title='goTitle';
insert Cnote;

ContentDocumentLink cdl = new ContentDocumentLink();
cdl.ContentDocumentId=Cnote.id;
cdl.LinkedEntityId='500P0000005bZv1';
cdl.Visibility='AllUsers';
cdl.ShareType='I';

insert cdl;