0

I've a frustrating problem while testing one class method. In my UnitTest I must create some QuoteLineItem and associate them to some Quotes. Now the issue is :

I create the QuoteLineItem, insert it with a Quantity and a UnitPrice, but debugging gives me null value both for SubTotal and TotalPrice. What am I missing to do?

QuoteLineItem teste1 = new QuoteLineItem(QuoteId=testa1.Id,UnitPrice=100,Discount=0, Quantity=1,Product2Id=prodotto.Id,PricebookEntryId=pbe1.Id);     
insert teste1;

system.debug('QUOTE ITEM subtotal: ' + teste1.SubTotal);     //it gives null
system.debug('QUOTE ITEM unitprice: ' + teste1.UnitPrice);   // it gives 100
system.debug('QUOTE ITEM quantity: ' + teste1.Quantity);/    /it gives 1
system.debug('QUOTE ITEM totalprice: ' + teste1.TotalPrice);  //it gives null
0

You will need to requery the QuoteLineItem to get the information from Formula fields. See the example below

QuoteLineItem teste1 = new QuoteLineItem(QuoteId=testa1.Id,UnitPrice=100,Discount=0, Quantity=1,Product2Id=prodotto.Id,PricebookEntryId=pbe1.Id);     
insert teste1;

QuoteLineItem qli = [select SubTotal, UnitPrice, Quantity, TotalPrice from QuoteLineItem where Id = :teste1.Id];
system.debug('QUOTE ITEM subtotal: ' + qli.SubTotal); 
system.debug('QUOTE ITEM unitprice: ' + qli.UnitPrice);
system.debug('QUOTE ITEM quantity: ' + qli.Quantity);
system.debug('QUOTE ITEM totalprice: ' + qli.TotalPrice); 
| improve this answer | |
  • It works, thanks! But still I have an issue, because I'm using quotelineItem simply to add them to reelative Quotes , because the thing I really need is to have (in test class) a quote with a non-null GrandTotal, and the only way for having it is to create some quotelineitem so that quote grand total is not null. So, can I reference , after querying, the myquote.GrandTotal so that it is not null? I don't know if i was clear enough, (if not, I'll try to explain better) – user9959 Sep 29 '14 at 13:56
  • hi @toninotrip, Im afraid I don't understand. If you post a new question and add some code I am be able to help. – BarCotter Sep 29 '14 at 14:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy