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
Sarah RobertsonSarah Robertson 

Help with test class coverage for adding items to list

Hi wondering if anyone can help me - i've got 60% coverage here where am i going wrong ? 

class:
public class LinuxITMigrationOpenOpps{
        
    public PageReference doMigration()
    {   
        LinuxITMigrationOpenOpps.doMigrationOpenOpps();
        PageReference pg=new pagereference('/001/o');
        pg.setredirect(true);
        return pg;
    }
    
    public PageReference doRemaining()
    {   
        LinuxITMigrationOpenOpps.remainingLinuxAccounts();
        PageReference pgr=new pagereference('/001/o');
        pgr.setredirect(true);
        return pgr;
    }
    
    public static void doMigrationOpenOpps()
    {    
        ApexPages.addmessage(new ApexPages.message(ApexPages.severity.info,'Opps migrating'));
        
        Map<id, Opportunity> oppMap = new Map<id, Opportunity>([SELECT id, Name, account.Name, accountid from Opportunity 
                                                                WHERE StageName in ('Stage 0: Lead','Stage 1: Suspect','Stage 2: Prospect','Stage 3: Best Case','Stage 4: Committed Deal') 
                                                                AND (Account.Support_Group__c = 'LinuxIT')
                                                                AND account.RecordType.Name ='UK Account']);
        
        List<Opportunity> oppList = new List<Opportunity>();
        // Update Opportunity by defaulting Campaign as Not Campaign Related
        for(Opportunity opp: oppMap.values()){
            //the campaign id for not campaign related 
            opp.CampaignId = '7013N0000004wea';
            oppList.add(opp);
            //System.debug(Logginglevel.INFO,'Opportunity ID -->'+opp.id);
        }
        update oppList;
        
        Map<id, OpportunityLineItem> oppLineItem = new Map <id, OpportunityLineItem>();
        List<OpportunityLineItem> oppLineItemList = new list<OpportunityLineItem>();
        
        for (OpportunityLineItem oli:[SELECT id, name, OpportunityId, Term_months__c, Contract_Length_Years__c, From_ARV__c, Old_ARV_If_Replacement__c, To_ARV__c, Sales_ARV__c, From_ARC__c, To_ARC__c, NRC__c
                                      FROM OpportunityLineItem 
                                      WHERE OpportunityId in :oppMap.keyset()]){
            oli.Term_months__c = oli.Contract_Length_Years__c * 12;
            oli.From_ARV__c = oli.Old_ARV_If_Replacement__c;
            oli.To_ARV__c = oli.Sales_ARV__c;
            oli.From_ARC__c = 0;
            oli.To_ARC__c = 0;
            oli.NRC__c = 0;
                                          
            oppLineItem.put(oli.OpportunityId, oli);
            oppLineItemList.add(oli);
        }
        update oppLineItem.values();
        
        System.debug('Number of Opportunities --> ' + oppMap.size());
        System.debug('Number of OpplineItems --> ' + oppLineItem.size());
        System.debug('Number of OpplineItems List--> ' + oppLineItemList.size());
        
        List <Account> accList = new list<Account>();
        Map<id, Account> accMap = new map<id, Account>([SELECT id, name, NumberOfEmployees, No_of_Employees__c, support_group__c, Total_Sales__c, ARV__c 
                                                        FROM Account 
                                                        WHERE id in (SELECT accountid 
                                                                     FROM Opportunity 
                                                                     WHERE id in:oppMap.KeySet())]);
        
        for(Account acc: accMap.values()){
            //System.debug('Account Name '+acc.Name);
            acc.Name = acc.name + ' (LinuxIT)';
            acc.No_of_Employees__c = String.valueof(acc.NumberOfEmployees);
            acc.support_group__c = 'MSP';
            acc.ARV__c = acc.Total_Sales__c;
            
            accList.add(acc);
        }
        update accList;
        
       // System.debug('Number of Accounts -->' + accMap.size());
        
        /*
        List<Contact> conlist= new List<Contact>();
        map<id, Contact> conmap = new map<id, Contact>([Select id, name, Primary_Contact__c, Primary_Sales_Contact__c, Work_Phone_Extension__c,
                                                        phone
                                                        from Contact where accountid in: accmap.keyset()]);
        
        //string forphone;
        for(Contact con: conmap.values()){
            //System.debug('Contact Name '+con.Name);
            //forphone = '';
            con.Primary_Sales_Contact__c = con.Primary_Contact__c;
            //forphone = String.valueof(Con.phone);
            //con.Work_Phone_Extension__c = forphone.left(6); //(Con.phone ==''?'':Con.phone);
            conlist.add(con);
        }
        System.debug('Number of Contacts -->'+conmap.size());
        update conlist; 
        */
    }
    
    public static void remainingLinuxAccounts(){
        ApexPages.addmessage(new ApexPages.message(ApexPages.severity.info,'Remaining Accounts migrating'));
        
        List <Account> accList = new list<Account>();
        Map<id, Account> accMap = new map<id, Account>([SELECT id, name, NumberOfEmployees, No_of_Employees__c, support_group__c, Total_Sales__c, ARV__c 
                                                        FROM Account 
                                                        WHERE support_group__c = 'LinuxIT' 
                                                        AND RecordType.Name ='UK Account']);
        
        for(Account acc: accMap.values()){
            //System.debug('Account Name '+acc.Name);
            acc.Name = acc.name + ' (LinuxIT)';
            acc.No_of_Employees__c = String.valueof(acc.NumberOfEmployees);
            acc.support_group__c = 'MSP';
            acc.ARV__c = acc.Total_Sales__c;
            
            accList.add(acc);
        }
        
        System.debug('Number of Accounts -->' + accList.size());
        //update accList;
    }
}


Test class

@isTest
public class LinuxITMigrationOpenOppsTest {
     static testmethod void LinuxITMigrationOpenOppsTest(){
        Test.startTest();
         
        Account Acc = new Account(name = 'test account',
                                  support_group__c = 'LinuxIT', 
                                  recordtypeid = '01220000000E1sfAAC', 
                                  Projected_FYCV__c = 10,   
                                  Turnover_currency__c = 10, 
                                  Company_Registered_Number__c ='1', 
                                  BillingStreet = '123', 
                                  Customer_Segment__c = 'SMB',
                                  Vertical_Classification__c = 'Gaming', 
                                  cf_customer_vertical__c = 'Finance', 
                                  cf_customer_segment__c = 'Corporate', 
                                  cf_customer_sector__c = 'Private');
        insert Acc;
        
         
        Contact con = new Contact(accountid = acc.id, 
                                  firstName = 'test first', 
                                  lastname = 'test last', 
                                  MobilePhone = '0123456789', 
                                  Direct_Dial__c = '0123456789', 
                                  Salutation = 'Mr');
        insert con;
        
         
        Product2 pd = new Product2(name= 'Test Product', 
                                   isActive = true, 
                                   CurrencyIsoCode = 'GBP');
        insert pd;
         
         
        Id pricebookId = Test.getStandardPricebookId(); // Standard price book entries require the standard price book ID.
        PricebookEntry standardPrice = new PricebookEntry(Pricebook2Id = pricebookId, 
                                                          Product2Id = pd.Id,
                                                          UnitPrice = 10000, IsActive = true);
        insert standardPrice; 
         
         
        Pricebook2 pb = new pricebook2(name ='Test PB', 
                                       isActive = true);
        insert pb;
                       
         
        PriceBookEntry pbe= new PriceBookEntry(pricebook2id = pb.Id, 
                                               product2ID = pd.id, 
                                               isActive = true, 
                                               UnitPrice = 10000, 
                                               UseStandardPrice = false, 
                                               CurrencyIsoCode = 'GBP');
        insert pbe;
         
         
        Campaign ca = new Campaign(name = 'Test Campaign',
                                   recordTypeID = '01220000000E1sB',
                                   isActive = true);
        insert ca;
        
        
        Opportunity opp = new Opportunity (accountid = acc.id, 
                                           name = 'test opp', 
                                           stageName = 'Stage 0: Lead', 
                                           closeDate = system.today(), 
                                           CampaignId = '7013N0000004wea', 
                                           LeadSource = 'Cold Call'); 
        insert opp;
        
       opp.CampaignId = '7013N0000004wea';
       
       update opp;

        
         system.assert(opp.CampaignId == '7013N0000004wea');
         
         
         
        List<Opportunity> oppList = new List<Opportunity>();
        oppList.add(opp);
        
         
        OpportunityLineItem oppLineItem = new OpportunityLineItem(opportunityid = opp.id, 
                                                                  pricebookentryid = pbe.id, 
                                                                  From_ARV__c = 10,
                                                                  To_ARC__c = 0,
                                                                  product2id = pd.id, 
                                                                  Quantity = 1, 
                                                                  UnitPrice = 750, 
                                                                  Term_months__c=12);
        insert oppLineItem;
        oppLineItem.From_ARV__c = oppLineItem.Old_ARV_If_Replacement__c;
        update oppLineItem; 
         
         
        LinuxITMigrationOpenOpps limo = new LinuxITMigrationOpenOpps();
        Pagereference pg1 = new Pagereference('/');        
        pg1 = limo.doMigration();
        pg1 = limo.doRemaining();
      
      
      
      
   
  }
      
         
         
       
           
}

 
Sarah RobertsonSarah Robertson
can no one help :( ?