You need to sign in to do that
Don't have an account?

Hi can anyone help me to write a test class for the following delete trigger
trigger TriggerTo_Delete_AccountLookup on Account (before delete) {
//To store parent ids
list<id> AccountIds=new list<id>();
for(Account accountVar:trigger.old)
{
AccountIds.add(accountVar.id);
}
//Collecting all child records related to Parent records
list<AccountLookup__c> listOfAccountLookup=[select Account_Name__r.Id from AccountLookup__c where Account_Name__r.Id in :AccountIds];
system.debug('listOfAccountLookup'+listOfAccountLookup);
//deleting child records
delete listOfAccountLookup;
All Answers
Private class DeleteAccountTest {
static testMethod void testMethod1() {
Account objAccTest = new Account ();
objAccTest.Name = 'TestAccount';
// Add other required fields here of account...
insert objAccTest;
AccountLookup__c objaccLookup = new AccountLookup__c ();
objaccLookup.Name = 'TestAccLookup';
objaccLookup.Account_Name__c = objAccTest.Id;
insert objaccLookup;
AccountLookup__c objaccLookupRec = [Select Account_Name__c From AccountLookup__c Where Id =: objaccLookup.Id ] ;
System.assertEquals(objaccLookupRec.Account_Name__c, objAccTest.Id);
Test.starttest();
delete objAccTest;
Test.stoptest();
}
}
TRY THIS CODE AND LET ME KNOW IF IT WORKS FOR YOU
THANKS
NIRAJ