You need to sign in to do that
Don't have an account?
Stephanie Zimmerman 7
Preventing Delete of Event when Running User is Not Equal to Created By
Hi, I have what I think should be a very simple trigger that is intended to prevent users from deleting Events unless they are the user that created it.
This is the code:
trigger NoDeleteonEvent on Event (before delete)
{
for (Event a : Trigger.old)
{
if (UserInfo.getUserId() != a.CreatedBy.Id)
{
a.addError('You cannot delete an event that was assigned to you by another person');
}
}
}
The problem is that the code prevents all users from deleting Events, even if they are the CreatedBy user. So I assume the problem is with this line ( if (UserInfo.getUserId() != a.CreatedBy.Id) ), though I'm not sure what the problem with it is.
Any advice is much appreciated. Thank you!
This is the code:
trigger NoDeleteonEvent on Event (before delete)
{
for (Event a : Trigger.old)
{
if (UserInfo.getUserId() != a.CreatedBy.Id)
{
a.addError('You cannot delete an event that was assigned to you by another person');
}
}
}
The problem is that the code prevents all users from deleting Events, even if they are the CreatedBy user. So I assume the problem is with this line ( if (UserInfo.getUserId() != a.CreatedBy.Id) ), though I'm not sure what the problem with it is.
Any advice is much appreciated. Thank you!
Use CreatedById instead of CreatedBy.Id . The above code should work.
All Answers
Use CreatedById instead of CreatedBy.Id . The above code should work.
<apex:page action="{!if($User.Alias !='hsohe' && $User.Alias != 'c62' && $User.Alias != 'brendon',
null,
urlFor($Action.Event.Delete, $CurrentPage.Parameters.id, [retURL='/00T'], true) ) }"
standardController="Event">
<apex:pageBlock >
<apex:PageMessage summary="You are not allowed to delete Events" severity="Warning" strength="3"/>
<apex:pageMessages /> </apex:pageBlock> </apex:page>