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
Rutul ShahRutul Shah 

System.UnexpectedException: Note can't be saved

I m getting error of System.UnexpectedException: Note can't be saved while inserting list of content notes like Database.insert(listContent,false)

What can be the issue?
sandeep@Salesforcesandeep@Salesforce
Hi Rutul, 

I am able to do it Here is below my code I have executed.Please give your sample code or review mine Where is difference?
ContentNote cn = new ContentNote();
cn.Title = 'test1';
String body = 'Hello World. Before insert/update, escape special characters such as ", ';
cn.Content = Blob.valueOf(body.escapeHTML4());
Database.insert(cn,false);

Thanks
Sandeep Singhal
http://www.codespokes.com/
Rutul ShahRutul Shah
Hello @sandeep,

have a look at my sample code which i tried and m getting the above error on Database.insert

        Database.SaveResult[] lsr=null;
        List<ContentNote> cntList=new List<ContentNote>();
        try {
                For(SyncDetail cnote : cnoteDetails){
                    String newTitle=cnote.getProperty('Title');
                    String newContent=cnote.getProperty('Content');
                    ContentNote objTempNote = new ContentNote();
                    objTempNote.Title =newTitle;
                    objTempNote.Content = Blob.valueOf(newContent.escapeHTML4());
                    cntList.add(objTempNote);
                }
                lsr= Database.insert(cntList, false);
                return lsr;
        }
        catch (Exception e) {
            System.Debug('Exception of insertContentNotes: ' + e.getMessage()+'    <======>    '+e.getStackTraceString());
            return lsr;
        }

 
Rutul ShahRutul Shah
Actually, I m not able to do any operation on ContentNote. Insert, Update, Delete and retrieve. I have written the test class for all 4 methods, but all are getting failed.
David M. ReedDavid M. Reed
ContentNotes will throw exceptions if the Content is not prepared exactly right. Contrary to the documentation, String.escapeHTML4() does not handle this correctly. I've written a package that attempts to correct for this: https://github.com/davidmreed/DMRNoteAttachmentImporter