How can I structure the opportunity line in Salesforce?

131    Asked by Deepabhawana in Salesforce , Asked on Mar 18, 2024

 I am a Salesforce administrator and I am responsible for setting up a new product catalog for an e-commerce company by using the Salesforce opportunity line items feature. How can I structure the opportunity line for this particular purpose? 

Answered by Csaba Toth

 In the context of Salesforce, you can structure the opportunity line in Salesforce for accommodating different product types, pricing models, and discounts by using the steps which are given below:-

Product catalog structure

You can define product families and create products. You can also set up price books for managing different pricing structures:-

// Create a Product Family and Product
Product2 product = new Product2();
Product.Name = ‘TV’;
Product.ProductCode = ‘TV001’;
Product.Family = ‘Electronics’;
Insert product;
// Create a Price Book
Pricebook2 standardPricebook = new Pricebook2();
standardPricebook.Name = ‘Standard Price Book’;
standardPricebook.IsActive = true;
insert standardPricebook;
Opportunity line items Configuration
You can add product to the appropriate price books with the specified list prices.
During creating the line opportunity try to reference the selected product and price book’ entry:-
// Associate Product with Price Book Entry
PricebookEntry pbe = new PricebookEntry();
Pbe.Pricebook2Id = standardPricebook.Id;
Pbe.Product2Id = product.Id;
Pbe.UnitPrice = 1000; // List price
Insert pbe;
// Create an Opportunity Line Item
Opportunity opp = new Opportunity();
Opp.Name = ‘New Opportunity’;
Opp.StageName = ‘Prospecting’;
Opp.CloseDate = Date.today() + 30;
Insert opp;
OpportunityLineItem oli = new OpportunityLineItem();
Oli.OpportunityId = opp.Id;
Oli.PricebookEntryId = pbe.Id;
Oli.Quantity = 2;
Oli.UnitPrice = pbe.UnitPrice;
Insert oli;
Pricing strategies

You can create separate price book’ entries for the bundle products and then add them to the appropriate price books.

// Create Price Book Entry for bundled product
PricebookEntry bundledPBE = new PricebookEntry();
bundledPBE.Pricebook2Id = standardPricebook.Id;
bundledPBE.Product2Id = bundledProduct.Id;
bundledPBE.UnitPrice = 1500; // List price for bundled product
insert bundledPBE;
// Create an Opportunity Line Item for bundled product
OpportunityLineItem bundledOLI = new OpportunityLineItem();
bundledOLI.OpportunityId = opp.Id;
bundledOLI.PricebookEntryId = bundledPBE.Id;
bundledOLI.Quantity = 1;
bundledOLI.UnitPrice = bundledPBE.UnitPrice;
insert bundledOLI;


Your Answer

Interviews

Parent Categories