Skip to content

Instantly share code, notes, and snippets.

@sakthivelsfdc
Created September 25, 2019 01:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sakthivelsfdc/f21c5ee54ffe369481f738dac37e72e1 to your computer and use it in GitHub Desktop.
Save sakthivelsfdc/f21c5ee54ffe369481f738dac37e72e1 to your computer and use it in GitHub Desktop.
trigger OpportunityDeleteTrigger on Opportunity ( before delete ) {
String name = [SELECT Name FROM Profile WHERE Id =:UserInfo.getProfileId()].Name;
if( name != 'System Administrator' ) {
if( Trigger.isBefore ) {
if( Trigger.isDelete ) {
for( Opportunity objOpportunity : Trigger.old ) {
if( objOpportunity.IsClosed == true ) {
objOpportunity.addError( 'This opportunity cannot be deleted becase it has been closed. Please contact Sales Operations.' );
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment