You need to sign in to do that
Don't have an account?
hanifa fatima
Here the trigger should fire when we delete the last child record of an account, it should throw an error saying that the last child cannot be be deleted.
How to write a delete trigger when deleting the last child contact of an Account
trigger DeletingChildRecor on Account (Before delete) { Set<Id> s=new Set<Id>(); for(Account a:Trigger.old) { System.debug('Adding ids'); s.add(a.id); } list<contact> ls=[select id,name from contact where contact.accountid=:s]; system.debug('About to Enter'); if(Trigger.isDelete) { system.debug('Entered'); if(ls.size()==1) { system.debug('Cant DELETE'); } } }
Here the trigger should fire when we delete the last child record of an account, it should throw an error saying that the last child cannot be be deleted.
You are doing event on contact so your trigger should be on that object "Contact".
And your trigger should be like this:
Let me know if solved your problem.
Thanks
Niraj