function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Darshit Pathak 3Darshit Pathak 3 

Why PricebookEntry Id is accepted instead of Product Id while creating OrderItem record in apex?

OrderItem object is a junction of Order and a product.
It has 2 lookup fields , 1 for Order (API : OrderId) and 1 for Product (API : Product2Id)
But when we try to create record of OrderItem it throws error Product2Id field does not exists.
Instead it's accepting "PricebookEntryId".
As per scheme it should accept Product Id and not the pricebookEntry Id.
yogesh_patilyogesh_patil
Product as a whole is generalized entity.

Pricebook refers to the price list of the products/entities for different regions.

PricebookEntryId refers to the price of a product from specified pricebook.

Hence the OrderItem accepts the pricebook entry id refering to the product from a specified pricebook rather than a generalized product.
Darshit Pathak 3Darshit Pathak 3
Thanks Yogesh for the response.
I agree on what you said but what I am not able to digest is , if PricebookEntry is required there then why lookup field would have been created by sfdc to refer Product2 Object?  how would a developer know by looking at schema of OrderItem that he needs to populate Pricebookentry id instead of Product Id.
Ramir Jr Quijada 7Ramir Jr Quijada 7
I agree with Darshit. Although this is an old thread.I still encounter it when creating OrderItem object. It is not visible on Schema Builder and on Object manager fields. Even when retrieved using 
sfdx force:source:retrieve -m CustomObject:Product2