• Hera Soherwardy
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 5
    Questions
  • 4
    Replies
The table would have 5 or 6 columns and multiple rows.
Each box would have a query / be filtered to include certain characteristics of a custom object.
What would the best approach to this be?

<apex:page action="{!if($User.Alias !='user1' && $User.Alias != 'user2' ,
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>
The table would have 5 or 6 columns and multiple rows.
Each box would have a query / be filtered to include certain characteristics of a custom object.
What would the best approach to this be?
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!

Hi all,

 

I have been looking into using a trigger to prevent Case deletion, the reason being that delete is required in order for the users to be able to mass update Cases from list views but we don't want any Cases deleted.

 

I'm not a developer by trade but my current trigger is below. It works as intended but I wanted to check if this is the best approach/ask for opmitisation advice, e.g. the best way to bulkify.

 

Thanks in advance.

 

trigger trg_CasePreventDelete on Case (before delete) {
//Trigger to prevent deletion of Cases other by profiles named below  
   
	String profileId=userinfo.getProfileId();
	String profileName=[Select Id,Name from Profile where Id=:profileId].Name;
	system.debug('ProfileName'+profileName);
    
	if(profileName != 'System Administrator')
    
	for (Case CasetoPrevent: trigger.old)
     
		{
        		CasetoPrevent.addError('You do not have permission to delete Cases');
		}
}