Print this page

Error while inserting the Opportunity Line Item - FIELD_INTEGRITY_EXCEPTION

Knowledge Article Number 000166658
Description
When inserting the OpportunityLineItem, you may receive the following error :-

------------------------- 
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] 
------------------------- 
Resolution
As PricebookEntryId is required field when inserting the OpportunityLineItem, user was getting this ID value by querying PriceBookEntry using the filter as "Product2.id" . 
 
List<PricebookEntry> pbe = [select id, name, CurrencyIsoCode from PriceBookEntry where Pricebook2id =: 'VALUE' and Product2.Id in: VALUE.keySet() ];

To resolve this issue , use "Product2Id" filter . For e.g :- 

List<PricebookEntry> pbe = [select id, name, CurrencyIsoCode from PriceBookEntry where Pricebook2id =: 'VALUE' and Product2Id in: VALUE.keySet() ];




promote demote