2

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 in advantage for any advice.

5

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.

  • Thank you very much! how can i create a PriceBookEntry from user interface? after i will store the pricebook id in a custom setting. – Enry Jul 4 '13 at 13:26
  • @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 '13 at 13:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.