You need to sign in to do that
Don't have an account?

Populate quote line items with opportunity line items
Hi,
I am trying to update a newly created quote with the line items from the opportuntiy it was created on.
This is for annual opportunities for support contracts and I have used a flow to create the new opportunity when it reaches 30 days before its close date which works fine. I then got stuck trying to create the quote, add the line items and also create a pdf template of the quote, so turned to try and do it via triggers.
So far, once the new opportunity is created, I have a trigger to create a new quote......how do I now update that quotes line items with the opportunity line items. Heres what I have so far and an new to development with apex and struggling as can be seen withthe mess below of how far away I am...: -
trigger addquotelineitems on Quote (after insert) {
Quote qot =trigger.new[0];
Opportunity oppId=[select id from Opportunity where id=:qot.OpportunityId];
List<OpportunityLineItem> opplines=[select id, quantity, PriceBookEntry.Product2Id
from OpportunityLineItem where OpportunityId=:oppId.id];
for(OpportunityLineItem oppline:opplines){
QuoteLineItem qli = new QuoteLineItem();
qli.UnitPrice = oppline.UnitPrice;
qli.Product2Id = oppline.PriceBookEntry.Product2Id;
qli.Quantity = oppline.Quantity;
qli.Description = oppline.Description;
insert qli;
}
}
After that I need to create a quote pdf using a template, but no idea if this is possible let alone how its done, I guess via a class or some sort
Thanks
I am trying to update a newly created quote with the line items from the opportuntiy it was created on.
This is for annual opportunities for support contracts and I have used a flow to create the new opportunity when it reaches 30 days before its close date which works fine. I then got stuck trying to create the quote, add the line items and also create a pdf template of the quote, so turned to try and do it via triggers.
So far, once the new opportunity is created, I have a trigger to create a new quote......how do I now update that quotes line items with the opportunity line items. Heres what I have so far and an new to development with apex and struggling as can be seen withthe mess below of how far away I am...: -
trigger addquotelineitems on Quote (after insert) {
Quote qot =trigger.new[0];
Opportunity oppId=[select id from Opportunity where id=:qot.OpportunityId];
List<OpportunityLineItem> opplines=[select id, quantity, PriceBookEntry.Product2Id
from OpportunityLineItem where OpportunityId=:oppId.id];
for(OpportunityLineItem oppline:opplines){
QuoteLineItem qli = new QuoteLineItem();
qli.UnitPrice = oppline.UnitPrice;
qli.Product2Id = oppline.PriceBookEntry.Product2Id;
qli.Quantity = oppline.Quantity;
qli.Description = oppline.Description;
insert qli;
}
}
After that I need to create a quote pdf using a template, but no idea if this is possible let alone how its done, I guess via a class or some sort
Thanks