You need to sign in to do that
Don't have an account?
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;
}}
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
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;
Hi,
Try it with after insert trigger