You need to sign in to do that
Don't have an account?

how to write a trigger to prevent a profile from deleting a change request
Hello Guys
am new to Apex code. I would like a trigger to prevent members of a profile from deleting a change. I have come up with this code but i get an error. Could you help me refine it.
trigger RestrictDelete on BMCServiceDesk__Change_Request__c (before delete) {
String ProfileId = UserInfo.getProfileId();
for (Change_Request a : Trigger.old)
IF(ProfileId!='profileid'))
{
a.addError('You cannot delete this record!');
}
}
am new to Apex code. I would like a trigger to prevent members of a profile from deleting a change. I have come up with this code but i get an error. Could you help me refine it.
trigger RestrictDelete on BMCServiceDesk__Change_Request__c (before delete) {
String ProfileId = UserInfo.getProfileId();
for (Change_Request a : Trigger.old)
IF(ProfileId!='profileid'))
{
a.addError('You cannot delete this record!');
}
}
Try with below code it wil help !!
Let me know if it helps !!
Thanks
Manoj
Can I ask why a trigger is needed for this instead of just removing the delete privlege at the Profile-level (admin task)? If the limitation is that you cannot edit the standard Profile provided by BMC, then I would recommend cloning the Profile in question to create a custom version of the standard Profile and use the custom version for all users needing the access instead writing code to address this need. Hope this helps.
Thanks,
David