• +91-8376990324
  • amitdsy@gmail.com
Home • • How to create Opportunity Line Item using Apex in Salesforce?

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.

Cheers!!!

Tags: ,
Apply For Trainer