Whenever new record is created into account object before this new record is inserted into account delete all the contact record with this account name drecord
trigger AcountConDelete on Account (before insert) {
set<String> namestr= new Set<String>();
for(Account acc:Trigger.new){
namestr.add(acc.name);// Adding name to set
}
List<Contact> tobedeleted= [select id,name from contact where name in :namestr];//quering the contacts with that name
if(tobedeleted.size()>0)
delete tobedeleted;
}
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Can you try the below Trigger on Account object.
Let me know if you face any issues.
If this solution helps, Please mark it as best answer.
Thanks,