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

unable to cover the below lines in my test class
private void saveUpdateAccountChange(Map<Id,Id> oppsChanged, Map<Id,Opportunity> newOpps, Map<Id,Opportunity> oldOpps) {
List<Account> accforUpdateList = new List<Account>();
Map<Id,Account> accountMap = new Map<Id,Account>([Select Id, Dell_Affinity_Id__c From Account Where Id in :oppsChanged.keySet() or id in :oppsChanged.values()]);
// Only Evaluate Logic for Opportunities that are Potentially Changing Their Account & Source Account Has Dell Affinity Id
for (Id oppId : newOpps.keySet()){
Id accIdOld = oldOpps.get(oppId).AccountId;
Id accIdNew = newOpps.get(oppId).AccountId;
if (accountMap.get(accIdNew).Dell_Affinity_Id__c == null) {
Account AccUpdate = accountMap.get(accIdNew);
accUpdate.Dell_Affinity_Id__c = accountMap.get(accIdOld).Dell_Affinity_Id__c;
accforUpdateList.add(accUpdate);
} else if (accountMap.get(accIdNew).Dell_Affinity_Id__c != accountMap.get(accIdOld).Dell_Affinity_Id__c) {
Trigger.newMap.get(oppId).addError(' Cannot change the Account of an Opportunity if the current and new Accounts have different Affinity Ids.');
}
}
if (accforUpdateList.size() > 0)
update accforUpdateList;
}
List<Account> accforUpdateList = new List<Account>();
Map<Id,Account> accountMap = new Map<Id,Account>([Select Id, Dell_Affinity_Id__c From Account Where Id in :oppsChanged.keySet() or id in :oppsChanged.values()]);
// Only Evaluate Logic for Opportunities that are Potentially Changing Their Account & Source Account Has Dell Affinity Id
for (Id oppId : newOpps.keySet()){
Id accIdOld = oldOpps.get(oppId).AccountId;
Id accIdNew = newOpps.get(oppId).AccountId;
if (accountMap.get(accIdNew).Dell_Affinity_Id__c == null) {
Account AccUpdate = accountMap.get(accIdNew);
accUpdate.Dell_Affinity_Id__c = accountMap.get(accIdOld).Dell_Affinity_Id__c;
accforUpdateList.add(accUpdate);
} else if (accountMap.get(accIdNew).Dell_Affinity_Id__c != accountMap.get(accIdOld).Dell_Affinity_Id__c) {
Trigger.newMap.get(oppId).addError(' Cannot change the Account of an Opportunity if the current and new Accounts have different Affinity Ids.');
}
}
if (accforUpdateList.size() > 0)
update accforUpdateList;
}
Hi Shravani,
Are you not able to cover the entire method or only few lines?
Inorder to cover the method you will have to explicitly call the methods if this is not part of a handler class for a trigger and is a controller for a visualforce page.
Prepare valida test data that matches your criteria for entering partions of the code. If the appropriate parameters defined in the methods are passed the code should get covered automatically
trigger AccountTrigger on Account (before insert) {
AccountTriggerHandler objClass = new AccountTriggerHandler();
objClass.validate(trigger.new);
}
public with sharing class AccountTriggerHandler {
public void validate(list<Account> lstAccount){
for(Account objAccount : lstAccount){
if(objAccount.Active__c){
objAccount.Activated_Date__c = date.today();
}
}
}
}
@IsTest
Public class AccountTriggerHandlerTest {
static testMethod void coverage() {
Account objA = new Account();
objA.Name = 'Test 01';
objA.Active__c = true;
insert objA;
list<Account> lstA = [Select Id, Activated_Date__c from Account where Id =: objA.Id];
system.assertEquals(lstA[0].Activated_Date__c, date.today());
}
}
Thanks
Vivian