You need to sign in to do that
Don't have an account?
David M. Reed
Apex: inserting ContentNote results in exceptions for Unicode characters, lost line breaks
I'm working on a Visualforce page to simplify logging of Activities. As a portion of this process, users are asked to enter supporting text, which is to be attached to the resulting Activity in a note record (I'm using the new ContentNote). What I keep encountering is two issues:
Error is in expression '{!save}' in component <apex:commandButton> in page log_activity: Class.LogActivityController.save: line 123, column 1"
Note that I do use String.escapeHTML4() to prepare the text. Based on my testing the exception appears to be thrown when Unicode characters are present. Am I failing to prepare Unicode text appropriately in some fashion I'm not aware of?
Does anyone have any ideas?
- In the resulting note, all line breaks are removed: all of the lines are run together with no intervening space.
- There is an exception thrown repeatedly as follows:
Error is in expression '{!save}' in component <apex:commandButton> in page log_activity: Class.LogActivityController.save: line 123, column 1"
Note that I do use String.escapeHTML4() to prepare the text. Based on my testing the exception appears to be thrown when Unicode characters are present. Am I failing to prepare Unicode text appropriately in some fashion I'm not aware of?
Does anyone have any ideas?
ContentNote n = new ContentNote(); if (task.Subject != null && task.Subject != '') { n.Title = task.Subject; } else { n.Title = 'Activity Notes'; } n.Content = Blob.valueOf(longDescription.escapeHtml4()); insert n; ContentDocumentLink cdl = new ContentDocumentLink(); cdl.ContentDocumentId = n.Id; cdl.LinkedEntityId = task.Id; cdl.Visibility = 'AllUsers'; cdl.ShareType = 'I'; insert cdl;
But you can refer the checkpoints and use similar filtering in your code
https://help.salesforce.com/apex/HTViewSolution?urlname=ContentNote-insert-error-Note-Can-t-Be-Saved-Because-It-Contains-HTML-Tags-Or-Unescaped-Characters-That-Are-Not-Allowed-In-A-Note&language=en_US
I still cannot get the system to accept Unicode input. Doing .escapeUnicode() doesn't change the behavior.
I have a similar issue and wrote a question which remains unanswered. Could anyone please help me?
Here is the link: https://developer.salesforce.com/forums/ForumsMain?id=9060G0000005i8FQAQ