You need to sign in to do that
Don't have an account?
Stéphane C.
Preventing from deleting closed won opportunities for non administrator
Hi,
I want to prevent a non administrator user to delete closed won opportunities.
I think a trigger can be a good solution.
Do you think this apex can work?
Thank you.
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.
Hi Stephane,
pls try some like this
All Answers
Please use below validation rule instead of trigger.your trigger also fine.
AND($Profile.Name <> "System Administrator",ISPICKVAL(stagename, "Closed Won"))
Hope This Helps.
If it helps you please mark it as Best Answer.
Thanks
Varaprasad
I think I read with this method that an user can always delete an opportunity by the list view. Is it true?
Thank you.
Hi Stephane,
pls try some like this
Hi Stephane,
sorry it should profileName != "System Administrator".
hope it helps,
Thanks,
Manohar
I test it but I have an issue with the code : line 5:26 no viable alternative at character '"' .
I cannot see where it comes from? Any idea?
Thank you.
Hi, is it something to do with double quotes? Pls try single quotes once.
let me know if this works.
Thanks
No idea?!
It works now.
Hi stephane,
can't see the diff :)
please mark my answer as a best answer if it helped.
Thanks,
Manohar
Wrong quotes in the code.
Thank you.
Any idea?
Any idea?
I cannot see what it is wrong.
Any help?
Please use below code once and test:
Thanks
Varaprasad
Do you think it is possible to test this too :
Thank you.
Just one more think.
Is it possible to extend it to the edit function? If I don't want a non-administrator user can edit an closed opportunity?
Thank you.
LockClosedWonOpportunityTrigger: execution of BeforeUpdate caused by: System.FinalException: SObject row does not allow errors: Trigger.bizkor_LockBilledOpportunityTrigger: line 8, column 1
Any idea ?
Is it possible to mix "before update" and "before delete" on the same script?
I have this error : Trigger: execution of BeforeUpdate caused by: System.FinalException: SObject row does not allow errors Trigger.bizkor_LockBilledOpportunityTrigger: line 8, column 1.
Thank you for the help.
Validatipn rule will not work in this case