“Note can't be saved” error on ContentNote insertHelp with “System.UnexpectedException: Note can't be saved” in batch apexSend chatter files with RESTTrigger on AccountCan't find Note API NameList of Special Character that not acceptable in Content Note conversionNew Notes (ContentNote) Note Sharing Settings via TriggerE-Mail Body to ContentNote. Note can't be saved because it contains HTML tagsHow to show error msg in ContentNote?Creation of ContentNotes in Apex suddenly failing with System.UnexpectedException: Note can't be saved errorContentNote not showing correctlybulk new note insert fails with too many dml statements
How do we improve the relationship with a client software team that performs poorly and is becoming less collaborative?
Are the number of citations and number of published articles the most important criteria for a tenure promotion?
Schoenfled Residua test shows proportionality hazard assumptions holds but Kaplan-Meier plots intersect
How is the claim "I am in New York only if I am in America" the same as "If I am in New York, then I am in America?
Mage Armor with Defense fighting style (for Adventurers League bladeslinger)
Pattern match does not work in bash script
Fully-Firstable Anagram Sets
Mathematical cryptic clues
Can an x86 CPU running in real mode be considered to be basically an 8086 CPU?
Can a Warlock become Neutral Good?
How does one intimidate enemies without having the capacity for violence?
"to be prejudice towards/against someone" vs "to be prejudiced against/towards someone"
How did the USSR manage to innovate in an environment characterized by government censorship and high bureaucracy?
How is it possible to have an ability score that is less than 3?
Why doesn't H₄O²⁺ exist?
How old can references or sources in a thesis be?
Did Shadowfax go to Valinor?
tikz: show 0 at the axis origin
Either or Neither in sentence with another negative
What is the offset in a seaplane's hull?
Why is consensus so controversial in Britain?
Is a conference paper whose proceedings will be published in IEEE Xplore counted as a publication?
Why is Minecraft giving an OpenGL error?
Why Is Death Allowed In the Matrix?
“Note can't be saved” error on ContentNote insert
Help with “System.UnexpectedException: Note can't be saved” in batch apexSend chatter files with RESTTrigger on AccountCan't find Note API NameList of Special Character that not acceptable in Content Note conversionNew Notes (ContentNote) Note Sharing Settings via TriggerE-Mail Body to ContentNote. Note can't be saved because it contains HTML tagsHow to show error msg in ContentNote?Creation of ContentNotes in Apex suddenly failing with System.UnexpectedException: Note can't be saved errorContentNote not showing correctlybulk new note insert fails with too many dml statements
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I'm trying to create ContentNote records from Note ones but it's always giving me this particular error:
FATAL_ERROR System.UnexpectedException: Note can't be saved
Code:
List<Note> noteLIST = [SELECT Id, Title, Body, OwnerId, Owner.Profile.Name, ParentId, IsPrivate, CreatedById, CreatedDate FROM Note WHERE Owner.Profile.Name LIKE 'current_profile_i_want_to_check'];
List<ContentNote> cnLIST = new List<ContentNote>();
for(Note n : noteLIST)
ContentNote cn = new ContentNote(Title = n.Title,
Content = Blob.valueOf(n.Body));
cnLIST.add(cn);
if(!cnLIST.isEmpty())
insert cnLIST;
I've checked this post: Help with "System.UnexpectedException: Note can't be saved" in batch apex but still not working.
apex lightning notes contentnote
add a comment |
I'm trying to create ContentNote records from Note ones but it's always giving me this particular error:
FATAL_ERROR System.UnexpectedException: Note can't be saved
Code:
List<Note> noteLIST = [SELECT Id, Title, Body, OwnerId, Owner.Profile.Name, ParentId, IsPrivate, CreatedById, CreatedDate FROM Note WHERE Owner.Profile.Name LIKE 'current_profile_i_want_to_check'];
List<ContentNote> cnLIST = new List<ContentNote>();
for(Note n : noteLIST)
ContentNote cn = new ContentNote(Title = n.Title,
Content = Blob.valueOf(n.Body));
cnLIST.add(cn);
if(!cnLIST.isEmpty())
insert cnLIST;
I've checked this post: Help with "System.UnexpectedException: Note can't be saved" in batch apex but still not working.
apex lightning notes contentnote
add a comment |
I'm trying to create ContentNote records from Note ones but it's always giving me this particular error:
FATAL_ERROR System.UnexpectedException: Note can't be saved
Code:
List<Note> noteLIST = [SELECT Id, Title, Body, OwnerId, Owner.Profile.Name, ParentId, IsPrivate, CreatedById, CreatedDate FROM Note WHERE Owner.Profile.Name LIKE 'current_profile_i_want_to_check'];
List<ContentNote> cnLIST = new List<ContentNote>();
for(Note n : noteLIST)
ContentNote cn = new ContentNote(Title = n.Title,
Content = Blob.valueOf(n.Body));
cnLIST.add(cn);
if(!cnLIST.isEmpty())
insert cnLIST;
I've checked this post: Help with "System.UnexpectedException: Note can't be saved" in batch apex but still not working.
apex lightning notes contentnote
I'm trying to create ContentNote records from Note ones but it's always giving me this particular error:
FATAL_ERROR System.UnexpectedException: Note can't be saved
Code:
List<Note> noteLIST = [SELECT Id, Title, Body, OwnerId, Owner.Profile.Name, ParentId, IsPrivate, CreatedById, CreatedDate FROM Note WHERE Owner.Profile.Name LIKE 'current_profile_i_want_to_check'];
List<ContentNote> cnLIST = new List<ContentNote>();
for(Note n : noteLIST)
ContentNote cn = new ContentNote(Title = n.Title,
Content = Blob.valueOf(n.Body));
cnLIST.add(cn);
if(!cnLIST.isEmpty())
insert cnLIST;
I've checked this post: Help with "System.UnexpectedException: Note can't be saved" in batch apex but still not working.
apex lightning notes contentnote
apex lightning notes contentnote
edited Apr 3 at 10:25
molinet
asked Apr 3 at 9:39
molinetmolinet
627
627
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
I'm the author of the ContentNote library referred to in the linked answer. I'll reiterate the things I'm aware of that you need to do to prepare note content for insertion:
- Replace all basic HTML characters (
<>"'&) with their corresponding
entities (&and friends). - Replace all line breaks with
<br>(taking care with Windows CRLF/Linux LF/Mac CR) - Replace
'with'. - Do not replace Unicode characters with entities. Other entities, including
', result in an exception. Unicode should be left as the bare characters. - Ensure that the source content is well-formed Unicode/UTF-8 and does not contain non-printable characters.
- The title must not be null, zero-length, or consist only of whitespace. The title need not be escaped.
Also note that
the API reference on ContentNote incorrectly specifies to use
String.escapeHTML4()to prepare content. This does not work.
Here's how I actually prepare notes there:
public void addNote(String title, String content, Id linkedTo, String visibility, String shareType)
ContentNote cn = new ContentNote();
if (title != null && title.normalizeSpace().length() > 0)
cn.Title = title;
else
cn.Title = 'Untitled Note';
cn.Content = Blob.valueOf(content.escapeXML().replace('rn', '<br>').replace('r', '<br>').replace('n', '<br>').replace(''', '''));
// Go on to insert the ContentNote
If you don't precisely meet the expectations, you'll get an UnexpectedException, which is uncatchable and unhandleable in the same way as a LimitException.
Existing App
You may also want to look at Doug Ayers' existing application for converting classic Notes into ContentNotes.
add a comment |
There are many things you need to reconsider in your code:-
- The contentNote object field Content is of type blob(base64) but you are trying to put string value. Use Blob.valueOf('')
- The createdById having properties as follows:- Create (for users assigned the Set Audit Fields Upon Creation permission), Defaulted on createFilter, Group, Sort, Update (for users assigned the Set Audit Fields Upon Creation permission). So if you have been assigned the Set Audit Fields Upon Creation permission, You can manipulate the CreatedBYId field.
- The CreatedDate having properties as follows:- Create (for users assigned the Set Audit Fields Upon Creation permission), Defaulted on createFilter, Group, Sort, Update (for users assigned the Set Audit Fields Upon Creation permission). So if you have been assigned the Set Audit Fields Upon Creation permission, You can manipulate the CreatedDate field.
- The OwnerId having properties as follows:- Create (for users assigned the Set Audit Fields Upon Creation permission), Defaulted on createFilter, Group, Sort, Update (for users assigned the Set Audit Fields Upon Creation permission). So if you have been assigned the Set Audit Fields Upon Creation permission, You can manipulate the OwnerId field.
- You may like to look on SharingPrivacy. It Controls sharing privacy for a file. Only administrators and file owners with Collaborator access to the file can modify this field. Default is Visible to Anyone With Record Access. When set to Private on Records, the file is private on records but can be shared selectively with others.
- Special Access Rules:- Enhanced Notes must be enabled.
As per your comments, below code might help you:-
ContentNote cn = new ContentNote();
cn.Title = 'test1';
String body = 'Hello World. Before insert/update, escape special characters such as ", ', &, and other standard escape characters.';
cn.Content = Blob.valueOf(body.escapeHTML4());
insert(cn);
The above code escapes any special characters so they are converted to their HTML equivalents.
Read more about them here:- ContentNote
Thanks for your response! I have theBlob.valueOf(n.Body)in my code but didn't write it in first place. I also removed CreatedBy, CreatedDate and Owner fields but it's giving me same error again.
– molinet
Apr 3 at 10:27
Can you make sure you have enabled the notes?
– sanket kumar
Apr 3 at 10:34
Yes, It's enabled. What I've seen is that if my Note's Body has line breaks it displays the error. If not it creates ContentDocumentLink record successfully. Edit: exact error: System.UnexpectedException: Note can't be saved because it contains HTML tags or unescaped characters that are not allowed in a Note.
– molinet
Apr 3 at 10:40
I have update in my answer. Please check them.
– sanket kumar
Apr 3 at 10:44
Thanks for the update! I'll try this after a meeting and write you with the result.
– molinet
Apr 3 at 10:53
|
show 1 more comment
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "459"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f256335%2fnote-cant-be-saved-error-on-contentnote-insert%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I'm the author of the ContentNote library referred to in the linked answer. I'll reiterate the things I'm aware of that you need to do to prepare note content for insertion:
- Replace all basic HTML characters (
<>"'&) with their corresponding
entities (&and friends). - Replace all line breaks with
<br>(taking care with Windows CRLF/Linux LF/Mac CR) - Replace
'with'. - Do not replace Unicode characters with entities. Other entities, including
', result in an exception. Unicode should be left as the bare characters. - Ensure that the source content is well-formed Unicode/UTF-8 and does not contain non-printable characters.
- The title must not be null, zero-length, or consist only of whitespace. The title need not be escaped.
Also note that
the API reference on ContentNote incorrectly specifies to use
String.escapeHTML4()to prepare content. This does not work.
Here's how I actually prepare notes there:
public void addNote(String title, String content, Id linkedTo, String visibility, String shareType)
ContentNote cn = new ContentNote();
if (title != null && title.normalizeSpace().length() > 0)
cn.Title = title;
else
cn.Title = 'Untitled Note';
cn.Content = Blob.valueOf(content.escapeXML().replace('rn', '<br>').replace('r', '<br>').replace('n', '<br>').replace(''', '''));
// Go on to insert the ContentNote
If you don't precisely meet the expectations, you'll get an UnexpectedException, which is uncatchable and unhandleable in the same way as a LimitException.
Existing App
You may also want to look at Doug Ayers' existing application for converting classic Notes into ContentNotes.
add a comment |
I'm the author of the ContentNote library referred to in the linked answer. I'll reiterate the things I'm aware of that you need to do to prepare note content for insertion:
- Replace all basic HTML characters (
<>"'&) with their corresponding
entities (&and friends). - Replace all line breaks with
<br>(taking care with Windows CRLF/Linux LF/Mac CR) - Replace
'with'. - Do not replace Unicode characters with entities. Other entities, including
', result in an exception. Unicode should be left as the bare characters. - Ensure that the source content is well-formed Unicode/UTF-8 and does not contain non-printable characters.
- The title must not be null, zero-length, or consist only of whitespace. The title need not be escaped.
Also note that
the API reference on ContentNote incorrectly specifies to use
String.escapeHTML4()to prepare content. This does not work.
Here's how I actually prepare notes there:
public void addNote(String title, String content, Id linkedTo, String visibility, String shareType)
ContentNote cn = new ContentNote();
if (title != null && title.normalizeSpace().length() > 0)
cn.Title = title;
else
cn.Title = 'Untitled Note';
cn.Content = Blob.valueOf(content.escapeXML().replace('rn', '<br>').replace('r', '<br>').replace('n', '<br>').replace(''', '''));
// Go on to insert the ContentNote
If you don't precisely meet the expectations, you'll get an UnexpectedException, which is uncatchable and unhandleable in the same way as a LimitException.
Existing App
You may also want to look at Doug Ayers' existing application for converting classic Notes into ContentNotes.
add a comment |
I'm the author of the ContentNote library referred to in the linked answer. I'll reiterate the things I'm aware of that you need to do to prepare note content for insertion:
- Replace all basic HTML characters (
<>"'&) with their corresponding
entities (&and friends). - Replace all line breaks with
<br>(taking care with Windows CRLF/Linux LF/Mac CR) - Replace
'with'. - Do not replace Unicode characters with entities. Other entities, including
', result in an exception. Unicode should be left as the bare characters. - Ensure that the source content is well-formed Unicode/UTF-8 and does not contain non-printable characters.
- The title must not be null, zero-length, or consist only of whitespace. The title need not be escaped.
Also note that
the API reference on ContentNote incorrectly specifies to use
String.escapeHTML4()to prepare content. This does not work.
Here's how I actually prepare notes there:
public void addNote(String title, String content, Id linkedTo, String visibility, String shareType)
ContentNote cn = new ContentNote();
if (title != null && title.normalizeSpace().length() > 0)
cn.Title = title;
else
cn.Title = 'Untitled Note';
cn.Content = Blob.valueOf(content.escapeXML().replace('rn', '<br>').replace('r', '<br>').replace('n', '<br>').replace(''', '''));
// Go on to insert the ContentNote
If you don't precisely meet the expectations, you'll get an UnexpectedException, which is uncatchable and unhandleable in the same way as a LimitException.
Existing App
You may also want to look at Doug Ayers' existing application for converting classic Notes into ContentNotes.
I'm the author of the ContentNote library referred to in the linked answer. I'll reiterate the things I'm aware of that you need to do to prepare note content for insertion:
- Replace all basic HTML characters (
<>"'&) with their corresponding
entities (&and friends). - Replace all line breaks with
<br>(taking care with Windows CRLF/Linux LF/Mac CR) - Replace
'with'. - Do not replace Unicode characters with entities. Other entities, including
', result in an exception. Unicode should be left as the bare characters. - Ensure that the source content is well-formed Unicode/UTF-8 and does not contain non-printable characters.
- The title must not be null, zero-length, or consist only of whitespace. The title need not be escaped.
Also note that
the API reference on ContentNote incorrectly specifies to use
String.escapeHTML4()to prepare content. This does not work.
Here's how I actually prepare notes there:
public void addNote(String title, String content, Id linkedTo, String visibility, String shareType)
ContentNote cn = new ContentNote();
if (title != null && title.normalizeSpace().length() > 0)
cn.Title = title;
else
cn.Title = 'Untitled Note';
cn.Content = Blob.valueOf(content.escapeXML().replace('rn', '<br>').replace('r', '<br>').replace('n', '<br>').replace(''', '''));
// Go on to insert the ContentNote
If you don't precisely meet the expectations, you'll get an UnexpectedException, which is uncatchable and unhandleable in the same way as a LimitException.
Existing App
You may also want to look at Doug Ayers' existing application for converting classic Notes into ContentNotes.
edited Apr 3 at 14:03
answered Apr 3 at 11:14
David Reed♦David Reed
39.1k82356
39.1k82356
add a comment |
add a comment |
There are many things you need to reconsider in your code:-
- The contentNote object field Content is of type blob(base64) but you are trying to put string value. Use Blob.valueOf('')
- The createdById having properties as follows:- Create (for users assigned the Set Audit Fields Upon Creation permission), Defaulted on createFilter, Group, Sort, Update (for users assigned the Set Audit Fields Upon Creation permission). So if you have been assigned the Set Audit Fields Upon Creation permission, You can manipulate the CreatedBYId field.
- The CreatedDate having properties as follows:- Create (for users assigned the Set Audit Fields Upon Creation permission), Defaulted on createFilter, Group, Sort, Update (for users assigned the Set Audit Fields Upon Creation permission). So if you have been assigned the Set Audit Fields Upon Creation permission, You can manipulate the CreatedDate field.
- The OwnerId having properties as follows:- Create (for users assigned the Set Audit Fields Upon Creation permission), Defaulted on createFilter, Group, Sort, Update (for users assigned the Set Audit Fields Upon Creation permission). So if you have been assigned the Set Audit Fields Upon Creation permission, You can manipulate the OwnerId field.
- You may like to look on SharingPrivacy. It Controls sharing privacy for a file. Only administrators and file owners with Collaborator access to the file can modify this field. Default is Visible to Anyone With Record Access. When set to Private on Records, the file is private on records but can be shared selectively with others.
- Special Access Rules:- Enhanced Notes must be enabled.
As per your comments, below code might help you:-
ContentNote cn = new ContentNote();
cn.Title = 'test1';
String body = 'Hello World. Before insert/update, escape special characters such as ", ', &, and other standard escape characters.';
cn.Content = Blob.valueOf(body.escapeHTML4());
insert(cn);
The above code escapes any special characters so they are converted to their HTML equivalents.
Read more about them here:- ContentNote
Thanks for your response! I have theBlob.valueOf(n.Body)in my code but didn't write it in first place. I also removed CreatedBy, CreatedDate and Owner fields but it's giving me same error again.
– molinet
Apr 3 at 10:27
Can you make sure you have enabled the notes?
– sanket kumar
Apr 3 at 10:34
Yes, It's enabled. What I've seen is that if my Note's Body has line breaks it displays the error. If not it creates ContentDocumentLink record successfully. Edit: exact error: System.UnexpectedException: Note can't be saved because it contains HTML tags or unescaped characters that are not allowed in a Note.
– molinet
Apr 3 at 10:40
I have update in my answer. Please check them.
– sanket kumar
Apr 3 at 10:44
Thanks for the update! I'll try this after a meeting and write you with the result.
– molinet
Apr 3 at 10:53
|
show 1 more comment
There are many things you need to reconsider in your code:-
- The contentNote object field Content is of type blob(base64) but you are trying to put string value. Use Blob.valueOf('')
- The createdById having properties as follows:- Create (for users assigned the Set Audit Fields Upon Creation permission), Defaulted on createFilter, Group, Sort, Update (for users assigned the Set Audit Fields Upon Creation permission). So if you have been assigned the Set Audit Fields Upon Creation permission, You can manipulate the CreatedBYId field.
- The CreatedDate having properties as follows:- Create (for users assigned the Set Audit Fields Upon Creation permission), Defaulted on createFilter, Group, Sort, Update (for users assigned the Set Audit Fields Upon Creation permission). So if you have been assigned the Set Audit Fields Upon Creation permission, You can manipulate the CreatedDate field.
- The OwnerId having properties as follows:- Create (for users assigned the Set Audit Fields Upon Creation permission), Defaulted on createFilter, Group, Sort, Update (for users assigned the Set Audit Fields Upon Creation permission). So if you have been assigned the Set Audit Fields Upon Creation permission, You can manipulate the OwnerId field.
- You may like to look on SharingPrivacy. It Controls sharing privacy for a file. Only administrators and file owners with Collaborator access to the file can modify this field. Default is Visible to Anyone With Record Access. When set to Private on Records, the file is private on records but can be shared selectively with others.
- Special Access Rules:- Enhanced Notes must be enabled.
As per your comments, below code might help you:-
ContentNote cn = new ContentNote();
cn.Title = 'test1';
String body = 'Hello World. Before insert/update, escape special characters such as ", ', &, and other standard escape characters.';
cn.Content = Blob.valueOf(body.escapeHTML4());
insert(cn);
The above code escapes any special characters so they are converted to their HTML equivalents.
Read more about them here:- ContentNote
Thanks for your response! I have theBlob.valueOf(n.Body)in my code but didn't write it in first place. I also removed CreatedBy, CreatedDate and Owner fields but it's giving me same error again.
– molinet
Apr 3 at 10:27
Can you make sure you have enabled the notes?
– sanket kumar
Apr 3 at 10:34
Yes, It's enabled. What I've seen is that if my Note's Body has line breaks it displays the error. If not it creates ContentDocumentLink record successfully. Edit: exact error: System.UnexpectedException: Note can't be saved because it contains HTML tags or unescaped characters that are not allowed in a Note.
– molinet
Apr 3 at 10:40
I have update in my answer. Please check them.
– sanket kumar
Apr 3 at 10:44
Thanks for the update! I'll try this after a meeting and write you with the result.
– molinet
Apr 3 at 10:53
|
show 1 more comment
There are many things you need to reconsider in your code:-
- The contentNote object field Content is of type blob(base64) but you are trying to put string value. Use Blob.valueOf('')
- The createdById having properties as follows:- Create (for users assigned the Set Audit Fields Upon Creation permission), Defaulted on createFilter, Group, Sort, Update (for users assigned the Set Audit Fields Upon Creation permission). So if you have been assigned the Set Audit Fields Upon Creation permission, You can manipulate the CreatedBYId field.
- The CreatedDate having properties as follows:- Create (for users assigned the Set Audit Fields Upon Creation permission), Defaulted on createFilter, Group, Sort, Update (for users assigned the Set Audit Fields Upon Creation permission). So if you have been assigned the Set Audit Fields Upon Creation permission, You can manipulate the CreatedDate field.
- The OwnerId having properties as follows:- Create (for users assigned the Set Audit Fields Upon Creation permission), Defaulted on createFilter, Group, Sort, Update (for users assigned the Set Audit Fields Upon Creation permission). So if you have been assigned the Set Audit Fields Upon Creation permission, You can manipulate the OwnerId field.
- You may like to look on SharingPrivacy. It Controls sharing privacy for a file. Only administrators and file owners with Collaborator access to the file can modify this field. Default is Visible to Anyone With Record Access. When set to Private on Records, the file is private on records but can be shared selectively with others.
- Special Access Rules:- Enhanced Notes must be enabled.
As per your comments, below code might help you:-
ContentNote cn = new ContentNote();
cn.Title = 'test1';
String body = 'Hello World. Before insert/update, escape special characters such as ", ', &, and other standard escape characters.';
cn.Content = Blob.valueOf(body.escapeHTML4());
insert(cn);
The above code escapes any special characters so they are converted to their HTML equivalents.
Read more about them here:- ContentNote
There are many things you need to reconsider in your code:-
- The contentNote object field Content is of type blob(base64) but you are trying to put string value. Use Blob.valueOf('')
- The createdById having properties as follows:- Create (for users assigned the Set Audit Fields Upon Creation permission), Defaulted on createFilter, Group, Sort, Update (for users assigned the Set Audit Fields Upon Creation permission). So if you have been assigned the Set Audit Fields Upon Creation permission, You can manipulate the CreatedBYId field.
- The CreatedDate having properties as follows:- Create (for users assigned the Set Audit Fields Upon Creation permission), Defaulted on createFilter, Group, Sort, Update (for users assigned the Set Audit Fields Upon Creation permission). So if you have been assigned the Set Audit Fields Upon Creation permission, You can manipulate the CreatedDate field.
- The OwnerId having properties as follows:- Create (for users assigned the Set Audit Fields Upon Creation permission), Defaulted on createFilter, Group, Sort, Update (for users assigned the Set Audit Fields Upon Creation permission). So if you have been assigned the Set Audit Fields Upon Creation permission, You can manipulate the OwnerId field.
- You may like to look on SharingPrivacy. It Controls sharing privacy for a file. Only administrators and file owners with Collaborator access to the file can modify this field. Default is Visible to Anyone With Record Access. When set to Private on Records, the file is private on records but can be shared selectively with others.
- Special Access Rules:- Enhanced Notes must be enabled.
As per your comments, below code might help you:-
ContentNote cn = new ContentNote();
cn.Title = 'test1';
String body = 'Hello World. Before insert/update, escape special characters such as ", ', &, and other standard escape characters.';
cn.Content = Blob.valueOf(body.escapeHTML4());
insert(cn);
The above code escapes any special characters so they are converted to their HTML equivalents.
Read more about them here:- ContentNote
edited Apr 3 at 10:43
answered Apr 3 at 10:20
sanket kumarsanket kumar
3,3532426
3,3532426
Thanks for your response! I have theBlob.valueOf(n.Body)in my code but didn't write it in first place. I also removed CreatedBy, CreatedDate and Owner fields but it's giving me same error again.
– molinet
Apr 3 at 10:27
Can you make sure you have enabled the notes?
– sanket kumar
Apr 3 at 10:34
Yes, It's enabled. What I've seen is that if my Note's Body has line breaks it displays the error. If not it creates ContentDocumentLink record successfully. Edit: exact error: System.UnexpectedException: Note can't be saved because it contains HTML tags or unescaped characters that are not allowed in a Note.
– molinet
Apr 3 at 10:40
I have update in my answer. Please check them.
– sanket kumar
Apr 3 at 10:44
Thanks for the update! I'll try this after a meeting and write you with the result.
– molinet
Apr 3 at 10:53
|
show 1 more comment
Thanks for your response! I have theBlob.valueOf(n.Body)in my code but didn't write it in first place. I also removed CreatedBy, CreatedDate and Owner fields but it's giving me same error again.
– molinet
Apr 3 at 10:27
Can you make sure you have enabled the notes?
– sanket kumar
Apr 3 at 10:34
Yes, It's enabled. What I've seen is that if my Note's Body has line breaks it displays the error. If not it creates ContentDocumentLink record successfully. Edit: exact error: System.UnexpectedException: Note can't be saved because it contains HTML tags or unescaped characters that are not allowed in a Note.
– molinet
Apr 3 at 10:40
I have update in my answer. Please check them.
– sanket kumar
Apr 3 at 10:44
Thanks for the update! I'll try this after a meeting and write you with the result.
– molinet
Apr 3 at 10:53
Thanks for your response! I have the
Blob.valueOf(n.Body) in my code but didn't write it in first place. I also removed CreatedBy, CreatedDate and Owner fields but it's giving me same error again.– molinet
Apr 3 at 10:27
Thanks for your response! I have the
Blob.valueOf(n.Body) in my code but didn't write it in first place. I also removed CreatedBy, CreatedDate and Owner fields but it's giving me same error again.– molinet
Apr 3 at 10:27
Can you make sure you have enabled the notes?
– sanket kumar
Apr 3 at 10:34
Can you make sure you have enabled the notes?
– sanket kumar
Apr 3 at 10:34
Yes, It's enabled. What I've seen is that if my Note's Body has line breaks it displays the error. If not it creates ContentDocumentLink record successfully. Edit: exact error: System.UnexpectedException: Note can't be saved because it contains HTML tags or unescaped characters that are not allowed in a Note.
– molinet
Apr 3 at 10:40
Yes, It's enabled. What I've seen is that if my Note's Body has line breaks it displays the error. If not it creates ContentDocumentLink record successfully. Edit: exact error: System.UnexpectedException: Note can't be saved because it contains HTML tags or unescaped characters that are not allowed in a Note.
– molinet
Apr 3 at 10:40
I have update in my answer. Please check them.
– sanket kumar
Apr 3 at 10:44
I have update in my answer. Please check them.
– sanket kumar
Apr 3 at 10:44
Thanks for the update! I'll try this after a meeting and write you with the result.
– molinet
Apr 3 at 10:53
Thanks for the update! I'll try this after a meeting and write you with the result.
– molinet
Apr 3 at 10:53
|
show 1 more comment
Thanks for contributing an answer to Salesforce Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f256335%2fnote-cant-be-saved-error-on-contentnote-insert%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown