function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Anshuman ParhiAnshuman Parhi 

Write a trigger to delete all the related contacts whenever associated account is deleted

Hello Guys

Any solution for this....Thanks in Advance
Best Answer chosen by Anshuman Parhi
CharuDuttCharuDutt
Hii Ayushman
Try Below Code
trigger testerreredffdf on Account (after delete) {
    set<id>lstIds = new set<id>();
    list<Contact>lstCon = new list<Contact>();
    for(Account Acc :trigger.old){
        lstIds.add(Acc.Id);
    }
		
    for(Contact con : [select id,name,AccountId From Contact where AccountId IN :lstIds]){
        lstCon.add(Con);
    }
    delete lstcon;
}
Please Mark It As best Answer If It Helps
Thank You!