i need an option to create a note preventing the edit and delete on notes for a particular custom object. i wrote a below trigger .. but it is restricting to create a note also.
trigger NoteTrigger on ContentDocument(before delete, before update) {
Schema.DescribeSObjectResult inv = Claim__c.sObjectType.getDescribe();
String invKeyPrefix = inv.getKeyPrefix();
List < Id > contentDocId = new List < Id > ();
Map < Id, Id > contDocLinkedMap = new Map < Id, Id > ();
if (trigger.IsDelete || trigger.IsUpdate) {
for (ContentDocument con: Trigger.old) {
contentDocId.add(con.Id);
}
for (ContentDocumentLink cdl: [SELECT ContentDocumentId, LinkedEntityId FROM ContentDocumentLink WHERE ContentDocumentId IN: contentDocId]) {
contDocLinkedMap.put(cdl.ContentDocumentId, cdl.LinkedEntityId);
System.debug('map ' + contDocLinkedMap);
}
for (ContentDocument cdoc: Trigger.new == null ? Trigger.old : Trigger.new) {
//contDocLinkedMap.get(cdoc.Id) will give the LinkedEntityId
if (invKeyPrefix == String.valueOf(contDocLinkedMap.get(cdoc.Id)).left(3) && cdoc.FileType == 'SNOTE') {
cdoc.adderror('Notes could not be Edited or deleted .');
}
}
}
}