function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
erika002erika002 

Delete button for owner of leads (others cannot delete!)

Hey,

 

I want to create a delete button for the owner of leads because I don't want others to delete the lead of a certain owner, even if they are above them in the hierarchy.

 

Is there somebody who has a code or something to solve this?

 

Thanks!

jkucerajkucera

Instead of a button, you can implement it using a trigger.  I don't know the syntax to get the clicker, but I'm pretty sure it's out there.

 

 

trigger preventDelete on Lead (before delete){

  for (Lead l:trigger.new){

   if (l.OwnerId!=<need to get the Id of the person that clicked the button>){

    l.LastName.addError('Only lead owners can delete leads.');

  }

 }

}