function readOnly(count){ }
Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
trigger DoNotDeleteAccountHavingRelatedContact on Account (before delete) { List<Account> accList = new List<Account>(); Set<id> accIdSet = new Set<id>(); for(Account acc : Trigger.old) { accIdSet.add(acc.id); } Map<Id, Account> accts = new Map<Id, Account>([Select Id, (Select Id from contacts) from Account where id in :accIdSet]); for(Account acc : Trigger.old) { if(accts.get(acc.id).contacts.size()>0) { acc.adderror('Account cannot be deleted'); } } }
Can you try the below trigger on Account.
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,