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
Manish DeshmukhManish Deshmukh 

How to restrict a custom user to edit Notes & attachment file

GhanshyamChoudhariGhanshyamChoudhari
You can write the trigger to restrict a user from edit
for Notes
trigger notetrigger on Note (before update) {
    for(Note n: trigger.new){
        n.addError('No edit allowed');
    }
}

for attachment
 
trigger notetrigger on attachment (before update) {
    for(attachment n: trigger.new){
        n.addError('No edit allowed');
    }
}

 
Manish DeshmukhManish Deshmukh
Hi Ghanshyam,
My Req. is System admin will edit or delete attachment File but Ohter user can only view these Notes and attachment.
GhanshyamChoudhariGhanshyamChoudhari
try below code
trigger notetrigger on Note (before update) {

    Id profileId=userinfo.getProfileId();
String profileName=[Select Id,Name from Profile where Id=:profileId].Name;
    if(profileName!='System Administrator'){
         for(Note n: trigger.new){
        n.addError('No edit allowed');
    }   
    }
}

 
Narender Singh(Nads)Narender Singh(Nads)
Hi Manish,
You can try this code:
trigger notetrigger on Note (before update) {

    
    Profile p=[Select Id from Profile where name='System Administrator')];
    for(Note n: trigger.new){
        if(p.id!=userinfo.getProfileId())
        n.addError('No edit allowed');
    }
}

let me know if it helps
Thanks!