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
Joshua MeyerJoshua Meyer 

Opportunity Products Not Cloning To Quote

Hi There!

I am using a trigger to to some calculations on quote line item which involves pulling a value from opportunity product if a corresponding opp product exists (for example when a quote is created vs when a quote line item is manually added). In my test class I create a quote as follows: 
 
Quote a1o1q1 = new Quote();
        a1o1q1.Name = 'a1o1q1';
        a1o1q1.Opportunity = a1o1;
        a1o1q1.OpportunityId = a1o1.Id;
        a1o1q1.Expiration__c = Date.parse('08/01/2018');
        a1o1q1.Net_Terms__c = 'Net 30';
        a1o1q1.Payment_Schedule__c = 'Annual';
        a1o1q1.Payment_Terms__c = 'None';
		a1o1q1.Discount_Special_Term_Explanation__c = 'none';
        a1o1q1.of_Hires__c = '1';
        a1o1q1.of_Employees__c = 1;
	    a1o1q1.Use_limited_to__c = '1';
        a1o1q1.ContactId = quoteContact.Id;
        a1o1q1.ShippingName = 'Test Name';
        a1o1q1.ShippingStreet = '123 Sesame Street';
        a1o1q1.ShippingCity = 'Pretend City';
        a1o1q1.ShippingPostalCode = '77546';
        a1o1q1.ShippingState = 'Texas';
        a1o1q1.ShippingCountry = 'USA';
        a1o1q1.Pricebook2Id = Test.getStandardPricebookId();
        
        List<Quote> quotes = new List<Quote>();
        quotes.add(a1o1q1);
        insert quotes;
Although there are Opportunity Products on the Opportunity I'm tying the quote to, they are not being created as line items on the quote. Here's a screen of my code coverage, you'll see that the qliOli (related opp product to the quote line item) is not being covered.

** Please note, this code is actually working in Sandbox. When I create a quote, the opportunity products push to quote line items. I just can't get the code coverage in my test class. Any help greatly appreciated. Thanks!

User-added image

 
Raj VakatiRaj Vakati
Hi Joshua, 
If I understand correctly, in your test you have to insert the Quote link item also to cover the code. 

Thanks, 
Raj 
Joshua MeyerJoshua Meyer
That part is covered in blue in the graphic because I manually inserted a quote line item. The question is can I simulate the creation of quote line items from opportunity products when the quote is created.