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

trigger to clone opportunity with opportunity products
How to clone opportunity with opp products in a trigger.
I have all my functionality set in trigger .I want Line items to be cloned to new cloned opportunities.
Please help
I have all my functionality set in trigger .I want Line items to be cloned to new cloned opportunities.
Please help
after inserting new opportunity list,
//inserting new opportunities.
insert Oppstoinsert;
//Query line items from main opportunity and save it in ProductList
ProductList=[Select opportunityId,quantity,UnitPrice,ListPrice,pricebookentryid,Discount,ServiceDate,Description from opportunitylineitem where opportunityId=:op.id];
for(opportunity opnew:oppstoinsert){
for(opportunitylineitem Product:ProductList){
Opportunitylineitem NewItem = new opportunitylineItem();
NewItem.opportunityId=opnew.id;
NewItem.quantity=Product.quantity;
NewItem.UnitPrice=Product.UnitPrice;
NewItem.pricebookentryid=Product.pricebookentryid;
linitem.add(NewItem);
}
}
insert linitem;
}
All Answers
after inserting new opportunity list,
//inserting new opportunities.
insert Oppstoinsert;
//Query line items from main opportunity and save it in ProductList
ProductList=[Select opportunityId,quantity,UnitPrice,ListPrice,pricebookentryid,Discount,ServiceDate,Description from opportunitylineitem where opportunityId=:op.id];
for(opportunity opnew:oppstoinsert){
for(opportunitylineitem Product:ProductList){
Opportunitylineitem NewItem = new opportunitylineItem();
NewItem.opportunityId=opnew.id;
NewItem.quantity=Product.quantity;
NewItem.UnitPrice=Product.UnitPrice;
NewItem.pricebookentryid=Product.pricebookentryid;
linitem.add(NewItem);
}
}
insert linitem;
}
Please can you post full code
Thanks & Regards
Paarth Jolly