I need to create a trigger that will prevent the deletion of a task by anyone other than the creator. I don't know about writing code so I'm hoping someone can help me out with this. It would be an assigned task on a custom object called Closings if that makes any difference. Help!?
trigger NoDeleteonAssignedTask on Task (before delete) {
String ProfileId = UserInfo.getProfileId();String UserID = Userinfo.getUserId(); List profiles=[select id from Profile where name='PB Administrator'];
if (1!=profiles.size()) { // unable to get the profiles - handle error } else {
for (Task a : Trigger.old)
IF(a.IsAssigned__c==True &&(UserID!=a.CreatedbyID && (profileId!=profiles[0].id ))) { Apexpages.addMessage(new Apexpages.message(ApexPages.Severity.ERROR,'deletetaskerror'));
String ProfileId = UserInfo.getProfileId();String UserID = Userinfo.getUserId();
List<Profile> profiles=[select id from Profile where name='PB Administrator'];
if (1!=profiles.size())
{
// unable to get the profiles - handle error
}
else
{
for (Task a : Trigger.old)
IF(a.IsAssigned__c==True &&(UserID!=a.CreatedbyID && (profileId!=profiles[0].id )))
{
Apexpages.addMessage(new Apexpages.message(ApexPages.Severity.ERROR,'deletetaskerror'));
}
}
}
}