3

in a trigger i'am going to create a new opportunitylineitem for an opportunity:

                 OpportunityLineItem newOpptLineItem = new OpportunityLineItem();
                 newOpptLineItem.OpportunityId = opptInserted.Id;
                 newOpptLineItem.=cs.OppProductCpvId__c; // FOR GIGABYTE
                 newOpptLineItem.Quantity = 1;                   
                 newOpptLineItem.PricebookEntryId = peWEBinteractive.Id;
                 opptLineItemsToInsert.add(newOpptLineItem);  

I want to set up a product for this new opportunitylineitem.

newOpptLineItem.ProductId isn't available.

Thanks!

1 Answer 1

7

OpportunityLineItems lookup to a PriceBookEntry rather than a Product.

PriceBookEntry is a junction object between PriceBook and Product. This is so that you can list the same Product in multiple PriceBooks to cater for various currencies / commercial offering.

I've explained this in a past answer with a diagram.

You will therefore need to set the PriceBookEntryId rather than the ProductId, which I see you are already doing. You therefore should just get rid of this line, and the association to the Product happens via the PriceBookEntry relationship.

1
  • @Enry Take a look at this login.salesforce.com/help/doc/en/products_createpb.htm. Its better if you query for the pricebook entry instead of storing in custom setting. The pricebookentry would vary for each product so saving in custom setting is not the right way
    – Prady
    Jul 4, 2013 at 13:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .