Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, field integrity exception: PricebookEntryId, unknown (versions 3.0 and higher must specify pricebook entry id; others must specify product id): [PricebookEntryId, unknown]
When adding a product to an Opportunity, you are creating an OpportunityLineItem record. This record acts as a link between the Opportunity and a specific product at a specific price. In Salesforce, this price is defined by a PricebookEntry record, not just the Product record. The PricebookEntry represents a product's price within a specific Price Book (e.g., Standard Price Book, US Price Book).
This error occurs because the code is attempting to create an OpportunityLineItem without providing the required PricebookEntryId. Modern Salesforce APIs require you to specify the exact price listing (PricebookEntryId) for the product you are adding to the Opportunity.
List<PricebookEntry> pbe = [select id, name, CurrencyIsoCode from PriceBookEntry where Pricebook2id =: 'VALUE' and Product2Id in: VALUE.keySet() ];
000383141

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.