You need to sign in to do that
Don't have an account?
DIVAKAR BABU 15
write a test class for this below trigger
/**
trigger fired on:- before delete
purpose :- restrict users not to delete Casecomments except System admin profile Users
**/
trigger restrictUsersFromDel on Case_Comment__c (before delete) {
if(trigger.isBefore && trigger.isdelete){
Profile SystemAdminId=[select id from Profile where Name='System Administrator' limit 1];
if(UserInfo.getProfileId() != SystemAdminId.Id){
for(Case_Comment__c oldcase:Trigger.old){
oldcase.adderror('You are not authorized to delete the record , please contact your system administrator');
}
}
}
trigger fired on:- before delete
purpose :- restrict users not to delete Casecomments except System admin profile Users
**/
trigger restrictUsersFromDel on Case_Comment__c (before delete) {
if(trigger.isBefore && trigger.isdelete){
Profile SystemAdminId=[select id from Profile where Name='System Administrator' limit 1];
if(UserInfo.getProfileId() != SystemAdminId.Id){
for(Case_Comment__c oldcase:Trigger.old){
oldcase.adderror('You are not authorized to delete the record , please contact your system administrator');
}
}
}
Greetings to you!
Please try the below code, I have tested in my org and it is working fine. Kindly modify the code as per your requirement.
Remember to replace - System Admin with the name of a Profile in your Org that has access to Case(Read/Write etc). And replace CaseComment if you are using a custom object.
I hope it helps you.
Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.
Thanks and Regards,
Khan Anas