• jrohrer
  • NEWBIE
  • 0 Points
  • Member since 2010

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies

Hi,

 

We are struggling with the code coverage for the Trigger below.  The Test Class code is below as well.  Any assistance and/or guidance would be greatly appreciated!!

 

Cheers,

Bindu & Jason

 

 

TRIGGER

trigger UpdateQuote on QuoteLineItem(before insert,before update)

{

        for(QuoteLineItem qout : trigger.New )

        {          

if(qout.Product_Name__c == 'Testing Product')

            {                                                 

if(qout.Annual_Vol__c <> NULL )

                {                                       

if(qout.Annual_Vol__c >=  0 && qout.Annual_Vol__c <= 100000)

                   {                       

                      qout.UnitPrice = 350 ;           

                   }

               }

              qout.Quantity = 1 ;    

           }

     }

 }   

 

 

 

 

TEST CLASS:

@isTest
   public class UpdateQuoteTest{
    //private static testmethod void testGetters()
    
    static testMethod void UpdateQuoteTest()
    {
       // Pricebook2 standardPB = [select id from Pricebook2 limit 1];
       
        Pricebook2 pb = new Pricebook2(Name = 'Standard Price Book 2009', Description = 'Price Book 2009 Products', IsActive = true );
        insert pb;
        Product2 prod = new Product2(Name = 'Testing Product', Family = 'Best Practices', IsActive = true);
        insert prod;
         List<Pricebook2> standardPbList = [select id, name, isActive from Pricebook2 where IsStandard = true ];
     //   PricebookEntry standardPrice = new PricebookEntry(Pricebook2Id = pb.Id, Product2Id = prod.Id, UnitPrice = 10000, IsActive = true, UseStandardPrice = false);
    //    insert standardPrice;
    List<PricebookEntry> listPriceBook = new List<PricebookEntry>();
     for(Pricebook2 p : standardPbList ){
      PricebookEntry pbe = New PricebookEntry ();
      pbe = new PricebookEntry(Pricebook2Id = p.Id, Product2Id = prod.Id, UnitPrice = 10000, IsActive = true, UseStandardPrice = false);
       listPriceBook.add(pbe);
     }
        insert listPriceBook;
        Opportunity opp = new Opportunity(Name = 'Test Syndicated 2010', Type = 'Syndicated - New', StageName = 'Planning', CloseDate = system.today());
        insert opp;
        List<OpportunityLineItem> opplineList = new List<OpportunityLineItem>();
       for(PricebookEntry pricebook : listPriceBook){
            OpportunityLineItem oli = new OpportunityLineItem ();
            oli  = new OpportunityLineItem(opportunityId = opp.Id, pricebookentryId = pricebook.Id, Quantity = 1, UnitPrice = 7500, Description = '2007 CMR #4 - Anti-Infectives');
            opplineList.add(oli);
       }
       insert opplineList;
     //   List<OpportunityLineItem> olis = [Select Id From OpportunityLineItem Where OpportunityId =: opp.Id];
     //   update olis[0];
        Quote quttest = new Quote (Name = 'qoutetest' , OpportunityId = opp.id , Pricebook2Id = pb.id );
        insert quttest ;
        List<QuoteLineItem> listval = new   List<QuoteLineItem>();
        Integer Annualvalue = 1000 ;
        for(PricebookEntry pricebook : listPriceBook){
            QuoteLineItem qutlineitemtest = new QuoteLineItem ();
            qutlineitemtest = new QuoteLineItem(QuoteId = quttest .id , Quantity = 3.00 ,Annual_Vol__c = Annualvalue ,UnitPrice = 12 , PricebookEntryId = pricebook.id);
            
            listval.add(qutlineitemtest);
            Annualvalue = Annualvalue + 1000;
         }
       insert listval;
    }
}