How do I cover the after undelete process in test class for the trigger. The lines which are not covering is below,
public void executeOnUnDeleteAccount(list<Account> accountNewList) {
set<ID> parentAccountIdSet = new set<ID>();
for (Account account : accountNewList) {
if(account.ParentId != null) {
// set parent Accounts
parentAccountIdSet.add(account.ParentId);
}
}
if(!parentAccountIdSet.IsEmpty() && parentAccountIdSet != null){
// fetch all child accounts
fetchAllChildAccounts(parentAccountIdSet);
}
}
**Test class **
@isTest
public class Account_AggregateMRROfChildAccountsTest {
public static testMethod void insertAccount() {
Account parentAccount = new Account();
parentAccount.Name = 'Test parent Account';
insert parentAccount;
Account childAccount = new Account();
childAccount.Name = 'Test child Account';
childAccount.ParentId = parentAccount.Id;
insert childAccount;
Opportunity opportunity = new Opportunity(AccountId = childAccount.Id,
Name = 'OpprtuityNAme1',
StageName = 'Prospecting',
CloseDate = Date.today());
insert opportunity;
//Created product line item for MMR__c field
Id pricebookId = Test.getStandardPricebookId();
Product2 p2 = new Product2(Name = 'Tes12 Product',
ProductCode = 'Pro-X',
isActive = true,
CanUseRevenueSchedule = true);
insert p2;
PricebookEntry pbe = new PricebookEntry(Pricebook2Id = pricebookId,
Product2Id = p2.Id,
UnitPrice = 99,
isActive=true);
insert pbe;
OpportunityLineItem oli = new OpportunityLineItem(PriceBookEntryId = pbe.Id,
OpportunityId = opportunity.Id,
Quantity = 1,
UnitPrice = 99);
insert oli;
}
public static testMethod void updateAccount() {
Account parentAccount = new Account();
parentAccount.Name = 'Test parent Account';
insert parentAccount;
Account childAccount = new Account();
childAccount.Name = 'Test child Account';
childAccount.ParentId = parentAccount.Id;
insert childAccount;
Opportunity opportunity = new Opportunity(AccountId = childAccount.Id,
Name = 'OpprtuityNAme1',
StageName = 'Prospecting',
CloseDate = Date.today());
insert opportunity;
//Created product line item for MMR__c field
Id pricebookId = Test.getStandardPricebookId();
Product2 p2 = new Product2(Name = 'Tes12 Product',
ProductCode = 'Pro-X',
isActive = true,
CanUseRevenueSchedule = true);
insert p2;
PricebookEntry pbe = new PricebookEntry(Pricebook2Id = pricebookId,
Product2Id = p2.Id,
UnitPrice = 99,
isActive=true);
insert pbe;
OpportunityLineItem oli = new OpportunityLineItem(PriceBookEntryId = pbe.Id,
OpportunityId = opportunity.Id,
Quantity = 1,
UnitPrice = 99);
insert oli;
Opportunity opportunity2 = new Opportunity(AccountId = childAccount.Id,
Name = 'OpprtuityNAme1',
StageName = 'Prospecting',
CloseDate = Date.today());
insert opportunity2;
Product2 p = new Product2(Name = 'Tes12 Product',
ProductCode = 'Pro-X',
isActive = true,
CanUseRevenueSchedule = true);
insert p;
PricebookEntry pbe1 = new PricebookEntry(Pricebook2Id = pricebookId,
Product2Id = p.Id,
UnitPrice = 99,
isActive=true);
insert pbe1;
OpportunityLineItem oli1 = new OpportunityLineItem(PriceBookEntryId = pbe1.Id,
OpportunityId = opportunity2.Id,
Quantity = 1,
UnitPrice = 99);
insert oli1;
}
public static testMethod void deleteAccount() {
Account parentAccount = new Account();
parentAccount.Name = 'Test parent Account';
insert parentAccount;
Account childAccount = new Account();
childAccount.Name = 'Test child Account';
childAccount.ParentId = parentAccount.Id;
insert childAccount;
delete childAccount;
Account[] savedAccts = [SELECT Id, Name FROM Account WHERE Name = 'test child KK 2' ALL ROWS];
undelete savedAccts;
}
}