I have to write a trigger to prevent deleting of Apartment records if there are flat records related to it
Here is my solution
.-------------
trigger DoNotDeleteAccountHavingRelatedContact on Apartment__c(before delete)
{
for(Apartment__c acc : [SELECT Id FROM Apartment__c WHERE Id IN (SELECT Apartment__c.id FROM Flat__c) AND Id IN :Trigger.oldMap.KeySet()]){
Trigger.oldMap.get(acc.Id).adderror('Account cannot be deleted');
}
}
Please help..Thank u in advance