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 ReadingAlex Reading 

Quote Line items from Opportunity Line Items

Hello All,

I currently have an APEX trigger which (when an opportunity has a QUOTE and is closed won), creates a second quote (which will be used as an invoice)

I was wondering if anyone can help me with possibly editing this code to also pull the Opportunity Line Items and add a quote line item for each one in the new automatically generated quote?

For example, If I have the Opportunity Line Item "Dog" from the "Animals" Pricebook at "$100" how can I change the code to not only automatically create the quote but also add a Quote Line Item for a $100 Dog?

Here is my code:

trigger InvoicefromQuote on Opportunity (after insert, after update) {
Map<Quote, Id> quoteMap = new Map<Quote, Id>();
for (Opportunity o : Trigger.new) {
if(o.isWon == true && o.HasQuote__c == true ){
Quote q = new Quote();
q.name = 'Quote-' + o.name;
q.opportunityId = o.id;
insert q;
quoteMap.put(q, o.accountId);
}
}
}

Any help you can provide would be great!


Thank you!


Ankit AroraAnkit Arora
Solutions are already on forums, here are some links which will help you :

https://developer.salesforce.com/forums?id=906F00000008llQIAQ

http://salesforce.stackexchange.com/questions/24209/trigger-to-add-products-to-opportunity-line-item-from-a-custom-object-without-pr

http://raydehler.com/cloud/clod/clone-a-quote-line-item-with-an-apex-controller.html
Paul Kim 24Paul Kim 24
Alex, did you ever get an answer from those other links? I'm having the same problem now.
Mitesh SuraMitesh Sura
I know this is old, but I would recommend using differnt object for Invoice. You can re-purpose Order object, if you are not using it for anything else.