Search

Thursday, 1 September 2011

Stopping records being changed other than by Sys Admin Users

This as an example will prevent anyone other than System Administrators to update any Notes

trigger UpdateNotes on Note (before update) {

public class myException extends Exception{}

Profile profileID = [Select id From Profile where Name Like 'System Administrator' LIMIT 1];
list<User> thisUser = [Select id,ProfileID From User where ProfileID !=: profileID.id and IsActive=true and id =:userinfo.getUserId() limit 1];

 if (thisUser.size() > 0){
     //not sys admin
     throw new myException('Cannot update');
 }

}

No comments:

Post a Comment

Note: only a member of this blog may post a comment.