+ Start a Discussion
Chidanand Magadum 24Chidanand Magadum 24 

Create OpportunityLineItem for an Opportunity

Hi guys,
How to create an Opportunity Line Item for an opportunity Using API?(Apex)
Himanshu ParasharHimanshu Parashar

List<PriceBookEntry> priceBookList = [SELECT Id, Product2Id, Product2.Id, Product2.Name FROM PriceBookEntry WHERE Product2Id='certain_id' AND PriceBook2.isStandard=true LIMIT 1];
OpportunityLineItem oli = new OpportunityLineItem();
oli.OpportunityId=oppty.Id;
oli.PricebookEntryId=priceBookList[0].Id 
/*rest of required fields*/
insert oli;
Arunkumar RArunkumar R
Hi Chidanand,

Please go through the below link it will helpful,

http://salesforcekings.blogspot.in/2014/06/how-to-insert-opportunity-record-with.html