+ Start a Discussion
cl0s3rcl0s3r 

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:

 

http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_erd_products.htm

 

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();
           a.name = 'test Account';
           insert a;

Pricebook2 pb = [SELECT Id, IsActive FROM PriceBook2 WHERE IsStandard=True];
Product2 p2 = new Product2();
p2.name = 'test p2';
insert p2;
 
PricebookEntry pbe = new PricebookEntry();
pbe.UnitPrice = 1;
pbe.Pricebook2Id = pb.id;
pbe.Product2Id = p2.id;
pbe.IsActive = true;
insert pbe;
 
Opportunity o = new Opportunity();
        
            o.AccountId = a.Id;
            o.Name = 'test';
            o.StageName = 'Prospecting';
            o.CloseDate = date.today();
            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.

Thanks!

Brad