• ankur koul
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hi,

I want to prevent a non administrator user to delete closed won opportunities.

I think a trigger can be a good solution.
 
trigger ClosedWonOpportunityTrigger on Opportunity (before delete) {
    for(Opportunity o: Trigger.Old)
        if($Profile.Name <> "System Administrator" && o.stagename=='Closed Won’)
        	o.addError(‘You cannot delete a Closed Won Opportunity. Please contact the Accounting Department. Thank you.’);
}

Do you think this apex can work?

Thank you.