function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Opportunity line item relationship

I need some assistance making a connection.  I would like to create a custom vf page to create the line items of an Opportunity. I follow the standard process and I see the lineitem.jsp page which I want to replace with a custom page, but don't understand the relationship to perform operation.

Cory CowgillCory Cowgill

You should review the Opportunity Line Item ER Diagram here:


Basically, you can use a standard controller of Opportuinty, and create an extensions for your custom VF Page.


Inside the Extension, build a query so that you grabe the objects in the ER Diagram.


pankaj kashyappankaj kashyap
It is not working because product2id and productcode is read only field  on OpportunityLineItem. and if u will try to add Product2
pankaj kashyappankaj kashyap
then it will give u an error...actuly i m also wand to develop the same navigation as salesforce provide but and getting this problem...
if any body know the solution plz post..

Brad BarrowesBrad Barrowes

Here's some code that will lay it out correctly:

Account a = new Account();
  = 'test Account';
           insert a;

Pricebook2 pb = [SELECT Id, IsActive FROM PriceBook2 WHERE IsStandard=True];
Product2 p2 = new Product2(); = 'test p2';
insert p2;
PricebookEntry pbe = new PricebookEntry();
pbe.UnitPrice = 1;
pbe.Pricebook2Id =;
pbe.Product2Id =;
pbe.IsActive = true;
insert pbe;
Opportunity o = new Opportunity();
            o.AccountId = a.Id;
            o.Name = 'test';
            o.StageName = 'Prospecting';
            o.CloseDate =;
            insert o;
OpportunityLineItem ol = new OpportunityLineItem();
            ol.OpportunityId = o.Id;
            ol.Quantity = 1;
            ol.UnitPrice = 2.00;
            ol.PricebookEntryId = pbe.Id;
            ol.Converted_to_Asset__c = false;
            ol.Description = 'testing testing';
            insert ol;

This is just a test class that lays everything out the way it needs to to successfully perform the insert and association of Opportunity Line Items.