anusha(salesforce developer)

Thursday, 5 January 2017

Deletion of account record should fail it has any contact records

 Deletion of account record should fail it has any contact records


trigger example6 on Account (before delete) {
    List<Account> accs=[select id,(Select id from Contacts) from Account where Id In:Trigger.Old];
    for(Account a:accs){
        if(a.contacts.size() > 0){
            a.addError('Account Record with contact can not be deleted');
        }
    }
}

No comments:

Post a Comment