function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
shravani milshravani mil 

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;
            } 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;
Vivian Charlie 1208Vivian Charlie 1208

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

shravani milshravani mil
am unable to cover entire method.and this is a handler trigger class can you give me some sample code 
Vivian Charlie 1208Vivian Charlie 1208

trigger AccountTrigger on Account (before insert) {
    AccountTriggerHandler objClass = new AccountTriggerHandler();

public with sharing class AccountTriggerHandler {
    public void validate(list<Account> lstAccount){
        for(Account objAccount : lstAccount){
                objAccount.Activated_Date__c =;

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];