User Story
I am a User.
WHEN I delete an Account
THEN the Accounts that have related Opportunities should not be deleted.
Code
trigger AccountTrigger on Account (before delete) {
List<Opportunity> relatedOPPList = [SELECT Id FROM Opportunity WHERE AccountId IN: Trigger.old];
if(relatedOppList.size()!=0){
Trigger.old[0].addError('An account with an opportunity can not be deleted');
}
}