You can have similar solution changing Api name and >5 for your scenario
trigger AccountContactCheck on Account (before delete) { for (AggregateResult ar : [SELECT accountid, count(id)size FROM contact where accountid in : Trigger.oldMap.keySet() GROUP BY accountid]) if(((integer)ar.get('size'))>0) trigger.oldMap.get((id)ar.get('accountid')).adderror('******* Contact is associated with it.you cant delete account'); }
https://salesforce.stackexchange.com/questions/191757/trigger-to-prevent-deletion-of-account-if-account-has-atleast-one-contact-associ
You can have similar solution changing Api name and >5 for your scenario
Thanks!
please use below approach
If you find your Solution then mark this as the best answer.
Thank you!
Regards,
Suraj Tripathi