You need to sign in to do that
Don't have an account?
Raghavendra Sharma 12
hi i am new in salesforce, my question is there are two custom object with a lookup relationship parent and child, and i want when parent record is delete all the child record is delete which is associated with that parent record
trigger deletes on parent__c (before delete) {
public set<id> h;
for(parent__c d:trigger.old)
{
h.add(d.name);
}
list<child__c> d=[SELECT name FROM child__c where link__c =: h ];
system.debug(d);
delete d;
}
public set<id> h;
for(parent__c d:trigger.old)
{
h.add(d.name);
}
list<child__c> d=[SELECT name FROM child__c where link__c =: h ];
system.debug(d);
delete d;
}
Hi,
if you use Master-Detail-Relationship (instead of a normal lookup), the deletion of the child happens automatically. You don't have to write an Apex-Trigger for that.
https://help.salesforce.com/articleView?id=overview_of_custom_object_relationships.htm&type=5