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.
Best Answer
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.