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
Alex PAlex P 

Test class for Quote Line Item VF component

Trying to test my first component for pulling quote line items into a VF email template. Any help greatly appreciated! 
VF Component:
<apex:component access="global" controller="SortedLineItemsController">
<apex:attribute name="value" type="Quote" assignTo="{!quote}" description="TODO: Describe me"/>

<apex:repeat var="li" value="{!sorted}">

<!-- Needed to work around limitation that the standard controller cannot "see"
the linkage between the value attribute and the opportunity property -->
<apex:variable var="oli" value="{!value.QuoteLineItems}" rendered="false">
Apex Controller:
public class SortedLineItemsController {
    public Quote quote { get; set; }
    public QuoteLineItem[] getSorted() {
        if (quote == null || quote.quoteLineItems== null) {
            return null;
        QuoteLineItem[] result = new QuoteLineItem[1];
        for (QuoteLineItem item : Quote.quoteLineItems) {
            result.add(0, item);
        return result;

Nalini ch 6Nalini ch 6

It looks like our team of experts can help you resolve this ticket. We have Salesforce global help-desk support and you can log a case and our Customer Success Agents will help you solve this issue. You can also speak to them on live chat. Click on the below link to contact our help-desk. Trust me it is a support service that we are offering for free!

Jarvis SFDC team
AbhishekAbhishek (Salesforce Developers) 
Hi Alex,

Follow the suggestions as mentioned in the below blogs,

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.


Alex PAlex P
I keep running into this error on my test class- System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATE_VALUE, This price definition already exists in this price book: []
private class TestSortedLineItemsController {
    @isTest static void insertOpp() {
        Account acc = new Account (name='Acme');
        insert acc;
        Contact con = new Contact(FirstName = 'First', LastName = 'Last', AccountId = acc.Id, Email = '');
        insert con;
        Opportunity opp= new Opportunity (); 'Testopp';
        opp.StageName= 'CAD Received';
        insert opp;

        Quote q= new Quote ();
        q.Name= 'Testq';
        insert q;
        Pricebook2 pb = new Pricebook2(Name = 'Services', Description = 'Price Book for all services', IsActive = true );
        insert pb;
        Product2 prod = new Product2(Name = 'CNC Machining', IsActive = true);
        nsert prod;
       PricebookEntry pbe=new PricebookEntry(unitprice=0.01,Product2Id=prod.Id, Pricebook2Id=Test.getStandardPricebookId(), IsActive= true); 
    insert pbe;    
        QuoteLineItem qli= new QuoteLineItem(,,,UnitPrice=pbe.UnitPrice,Quantity=4);
        insert qli;
        opp.StageName= 'Closed Won';

        SortedLineItemsController slic = new SortedLineItemsController();
        List<QuoteLineItem> slic_q = slic.getSorted();
        QuoteLineItem[] slic_qli = slic.getSorted();