You need to sign in to do that
Don't have an account?
A trigger on Account can't be deleted. when Account has Contact ot Opportunity.
I hope we are aware of the relationship among the standard Objects Account , Contact and Opportunity.
An Account is the master object of Contacts and Opportunity. So an Account may have or may not have Contact and/or Opportunity.
See, Go to any Account record, then scroll down to related lists like Contacts and Opportunities. If there is any Contact or Opportunity for that Account, now if you click on delete button of that Account it should not get deleted.
If there is no Contact or Opportunity for that then it should have to get deleted if you click the delete button.
So Will you Anyone to write a trigger on Account that should have to work as above.
You can just write a before delete trigger to query for Contacts/Opportunities and use the addError() method if any exist.
trigger deltrig on Account (before delete) {
for(account a:trigger.old)
{
if([select count() from contact where accountid=:a.id]>2)
a.adderror('Minimum 1 contact should b there');
}
}