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
venkateshyadav1243venkateshyadav1243 

Test class for quote line item

Hi this is my trigger and class

my trigger is doing increasing the filed count

 

here my trigger and test class

am not able to cover the test code

can any one tel me where am missing

am not getting error but its not going to cover the test coverage

thanks for your help

 

 

trigger UpdateNum on QuoteLineItem (before insert)
{
    if(trigger.isinsert)
    {
    QuoteLineItem QtItem=trigger.new[0];
      List<QuoteLineItem> QtLINum=[Select q.Id from QuoteLineItem q where q.QuoteId=:QtItem.QuoteId];
           if(QtLINum.size()>0)
           {
               Integer num=QtLINum.size();
               QtItem.Number__c=num+1;
           }
           else
           {
               QtItem.Number__c=1;
           }
    }
}



@istest
public class Test_QuoteLineItem
{
public static testmethod void T_QuoteLineItem()
{
op.Name='test';
op.StageName='closed last';
op.CloseDate=system.today();
insert op;
Pricebook2 stdPb = [select Id from Pricebook2 where isStandard=true limit 1];
        
        Product2 p = new product2(name='Abhi',family='Abhi',productcode='12345');
        insert p;
        System.debug('### p:'+p);
        
        PricebookEntry pbe = new PricebookEntry(pricebook2id=stdPb.id, product2id=p.id,
                                              unitprice=1.0, isActive=true,UseStandardPrice=false);
        insert pbe;
Quote q=new Quote();
q.Name='test1';
q.OpportunityId=op.id;
q.pricebook2id=stdPb.id;
insert q;

QuoteLineItem qli = new QuoteLineItem(quoteId=q.Id,
                                pricebookentryid=pbe.id, unitprice=1.5, quantity=2,Number__c=1);
        insert qli;
}}

hitesh90hitesh90

Hi venkat,

 

write @istest(seealldata=true) instead of @istest in your test class

 

Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other benefits.
 
Thank You,
Hitesh Patel
SFDC Certified Developer & Administrator

venkateshyadav1243venkateshyadav1243

Hi i tried the same but its not increase any code  coverage am not able to cover these 2 lines

 

 

Integer num=QtLINum.size();
               QtItem.Number__c=num+1;

Sfd developerSfd developer

Hi,

 

Try it with after insert trigger