This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @author Manoj Dega | |
* @date 21 July 2018 | |
* @description Restrict to non-admin users to delete the tasks | |
*/ | |
trigger DeleteTaskAdmin on Task (before delete) { | |
Id profileId = UserInfo.getProfileId(); | |
Id sysProfileId = [SELECT Id FROM Profile WHERE Name = 'System Administrator'].Id; | |
if(trigger.isBefore && trigger.IsDelete) { | |
if(profileId != sysProfileId) { | |
for(Task tsk : trigger.old) { | |
tsk.addError('You do not have rights to delete this record. Please contact with you System Administrator'); | |
} | |
} | |
} | |
} |