How to create Opportunity Line Item using Apex in Salesforce?

Sample Code:

OpportunityLineItem OLI = new OpportunityLineItem();
OLI.OpportunityId = oppty.Id; //Opportunity Id has to be assigned
OLI.PricebookEntryId = PBE.Id; //PriceBookEntry Id for that Product should be assigned.
OLI.Quantity = 1;
OLI.UnitPrice = PBE.UnitPrice;
insert OLI;

We cannot assign Product2Id to OpportunityLineItem.


No comments:

Post a Comment

Sharing is Caring!!! Share this with your friends!!!

submit to reddit