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
Deepak_KumarDeepak_Kumar 

How I can prevent users to update the contentnote?

I want to prevent users to update the Note(ContentNote) once it is created using the trigger or any other techniques?
Raj VakatiRaj Vakati
Try this
 
trigger ContentNoteTrigger on ContentDocument (before update) {
    for (ContentDocument origCd : Trigger.new) {
        ContentDocument cd = Trigger.newMap.get(origCd.Id);
        ContentDocument oldCd = Trigger.oldMap.get(origCd.Id);
        if (cd.FileType == 'SNOTE') {  // if it is a ContentNote
            Boolean titleChanged = (cd.Title != oldCd.Title);
            System.debug('Title: ' + cd.Title);
            System.debug('Old Title: ' + oldCd.Title + ', Title changed? ' + titleChanged);
            if (titleChanged) {
                cd.Title.addError('Cannot change the title of a Usage Note! Please keep the original Usage Note title.');  // Displays an JS alert() message preventing user from saving the ContentNote
            }
        }
    }
}

 
Deepak_KumarDeepak_Kumar
Hey Raj Vakati,
Here is the issue.
https://monosnap.com/file/NUpokIfXhXiQRo1sz4V1qYLU1lfqDR (https://monosnap.com/file/NUpokIfXhXiQRo1sz4V1qYLU1lfqDR" target="_blank)

I'm not able to save the note for the first time as well.

Thanks.
 
Raj VakatiRaj Vakati
Try this
 
trigger NoteTrigger on Note (before update) {
    
 List<Note> notes =(List<Note>)Trigger.new ;
 Map<Id,Note> oldVal = Trigger.oldMap ; 
 
 for(Note n :notes){
 if(n.Title != oldVal.get(n.Id).Title){
 n.Title.addError('Cannot change the title of a Usage Note! Please keep the original Usage Note title.');
 }
 }
 
    
}

 
Deepak_KumarDeepak_Kumar
Hi Raj Vakati,
It is still not working.
Thanks