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
ckellieckellie 

Compile Error: SObject constructor must use name=value pairs at line 18 column 30

In overriding the new quoteentry page with a visualforce page, QuoteLineItems are not added to the Quote based on the OpportunityLineItems. To bring this functionality I am writing an after insert trigger to clone the OpportunityLineItems to the QuoteLineItems when a quote is created. I am receiving the following error:

 

Error: Compile Error: SObject constructor must use name=value pairs at line 18 column 30

 

Here is my apex code:

 

trigger NewQuoteLineItems on Quote (After Insert) {

    Set<Id> qid = new Set<Id>();
    for(Quote q : Trigger.new){
        System.debug('**** 0 q id : '+q.Opportunityid); 
        qid.add(q.opportunityid);
    }
    System.debug('****1 : q Id size '+ qId.size());
    
    List<QuoteLineItem> qli = new List<QuoteLineItem>();

    List<OpportunityLineItem> oli = new List<OpportunityLineItem>([select id, opportunityid, pricebookentryid,
        Quantity, TotalPrice
        from OpportunityLineItem where opportunityid = :qid]);
   
    for(Quote quote : System.Trigger.new){

        QuoteLineItem item = new QuoteLineItem (
        
            qli[0].pricebookentryid = oli.pricebookentryid);
            
            qli.add(item);
    }
    insert qli;
}

 

I believe my trigger should generate a list of products attadched to the related opportunity and then create the same products on the quote record using a for loop. Is this the correct way? The above code is my start to the trigger.

 

Thank you,

ckellie

Best Answer chosen by Admin (Salesforce Developers) 
MiddhaMiddha

You are missing to close the round braces.

 

QuoteLineItem item = new QuoteLineItem ()

All Answers

MiddhaMiddha

You are missing to close the round braces.

 

QuoteLineItem item = new QuoteLineItem ()

This was selected as the best answer
ckellieckellie

Thank you very much for your help.