Skip to main content
format code
Source Link
Dave Humm
  • 5.1k
  • 5
  • 25
  • 38

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'); } }

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

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

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

Source Link

Trigger to prevent deletion of apartment if flat is associated with it

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