I have a custom object let say as Merchant__c. I also created a lookup field in my Account object which is related to my Merchant__c object.Deleted to Account delete all related Merchant__c record.
trigger DeleteAllRelatedMerchant on Account (Before Delete) {
set<ID> accountSet = new set<ID>();
for(Account a :trigger.old){
accountSet.add(a.ID);
}
list<Merchant__c> merchantList = [SELECT Id,name from Merchant__c where Account__c IN:accountSet];
delete merchantList;
}
trigger DeleteAllRelatedMerchant on Account (Before Delete) {
set<ID> accountSet = new set<ID>();
for(Account a :trigger.old){
accountSet.add(a.ID);
}
list<Merchant__c> merchantList = [SELECT Id,name from Merchant__c where Account__c IN:accountSet];
delete merchantList;
}
Thanks Vishvendra.Its very helpful to me..
ReplyDelete