What are Opportunity Line Items? The Products connected to an Opportunity are called OpportunityLineItem. There are many different things that a business might sell. These…
//First Step to create a new opportunity and Insert it Opportunity opp = new Opportunity(name='Any Name', ); insert opp; Pricebook2 standardPb = [select id, name, isActive from Pricebook2 where IsStandard = true limit 1]; Product2 prod = new Product2(); // ----> Create product prod.Name='Test Product'; insert prod; //------->Create PriceBookEntry PricebookEntry pbEntry = new PricebookEntry (); pbe1.Product2ID=prd1.id; pbEntry.Pricebook2ID=standardPb.id; pbEntry.UnitPrice=50; pbEntry.isActive=true; insert pbEntry; //-->Create OpportunityLineItem OpportunityLineItem oppLI = new OpportunityLineItem(); oppLI.PricebookEntryId= pbEntry.Id; oppLI.OpportunityId = opp.Id; oppLI.Quantity = 5; oppLI.TotalPrice = 10.0; insert opLineItemlist;
There was a problem reporting this post.
Please confirm you want to block this member.
You will no longer be able to:
Please note: This action will also remove this member from your connections and send a report to the site admin. Please allow a few minutes for this process to complete.