+ Start a Discussion
SFDC@ErrorSFDC@Error 

automatically create quote line item and add opportunity line item as quote line item

How can i automatically create quote line item and add opportunity line item as quote line item when i will create Quote .I Have tried this trigger which is not working as per my requirement .
trigger createQuoteLineDetails on CQuote__c(after insert,before insert) {

CQuote__c ord=trigger.new[0];

// Fetch Opp Id
COpportunity__c oppId=[select id from COpportunity__c where id=:ord.QOpp_Name__c];

// Fetch Opp Lines 
List<Opportunity_LineItem__c> opplines=[select id,CurrencyIsoCode,Opportunity__r.name,Principal_Name__c, Product_Category__c,Product_Description__c,
                        Product__c,Quantity__c,Unit_Price__c from Opportunity_LineItem__c where Opportunity__c=:oppId.id];

    // Loop Opportunity Lines
    for(Opportunity_LineItem__c oppline:opplines){
        
        // Create Order Line Object
        Quote_Line_Item__c QLine = new Quote_Line_Item__c ();
        QLine.Quote_Name__c= ord.Id;
       
       
        insert QLine ;
    }

}

 
EldonEldon
Hi,

When you create a quote from an opportunity, Salesforce creates QuoteLineItems based on the OpportunityLineItems of the parent opportunity, and it copies all the standard field values automatically. You dont need to write a trigger here.  

Regards
SFDC@ErrorSFDC@Error
Hay batman First check my requirement ,here all object are custom object
EldonEldon
Refer this blog by Doug Ayers for populating custom fields from OpportunityLineItems to QuoteLineItems.
https://douglascayers.com/2017/03/25/copy-opportunity-line-item-custom-fields-to-new-quote-line-items/

PS: Please specify your requirements properly in words.