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
CushtyCushty 

Add quote line items to new quote

Hi,

I have created a flow and process builder which will clone an Opportunity and add the line items, works fine.  What I want to do now is once that new opportunity is created, create a quote on it and add the quote line items (add the opportunity line items, the same as it does normally if you created a quote on an Opp) and then create a pdf on that quote.

I have tried to create another flow to add to my process builder for the quote creation and quote line items to create the quote and add the line items but nothing happens, no quote created, no line items, so I need to know what I am doing wrong, no error message.....I need to know how to do this so I can find out where I am going wrong. 

I have also tried writing a trigger for this quote creationa nd line items and got as far as creating the quote, but do not know how to add the line items to that quote noce its created and then create a PDF template on that quote.

Would it be best to go down the trigger route or should I try and get my flow working if that way is possible?
Thanks
 
Deepak GulianDeepak Gulian
Trigger route is best for this!
CushtyCushty
Ok....I have this as a trigger on opportunity to create a quote once my auto opp is created: -

trigger QuoteCreate on Opportunity (after insert) {
    
        List<Id> oppIdsList = new List<Id>();
        List<Quote> quoteList = new List<Quote>();
         
         for (Opportunity o : Trigger.new) {
        if(o.FME_AMC_Renewal__c == True)
        
        oppIdsList.add(o.id);
}
        Opportunity[] oppList = [SELECT name, id, account.billingStreet, account.billingCity,
                                    account.billingState, account.billingCountry
                                FROM Opportunity
                                WHERE id IN :oppIdsList];
        for (Opportunity o : oppList) {
        Quote q = new Quote();
        q.name = o.name;
        q.opportunityId = o.id;
        q.billingStreet = o.account.billingStreet;
        q.billingCity = o.account.billingCity;
        q.billingState = o.account.billingState;
        q.billingCountry = o.account.billingCountry;
    quoteList.add(q);
    }
    insert quoteList;
}

How Do I write one to copy the Opportuntiy line items over to be quote line items and thne how on earth do I create a pdf from this?