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
Ian Lin 439Ian Lin 439 

Required fields are missing: [Price Book Entry] when inserting order and orderitems

SwethaSwetha (Salesforce Developers) 
Hi Ian,
I assume you are seeing this error in a test class? If so, as the error suggests, you need to insert a pricebookEntry
PriceBookEntry stdPriceBookEntry = new PriceBookEntry();
stdPriceBookEntry.Product2Id=p.Id; //Product Id
stdPriceBookEntry.Pricebook2Id=Test.getStandardPricebookId();;
stdPriceBookEntry.UnitPrice=2000;
stdPriceBookEntry.IsActive=true;
insert stdPriceBookEntry;

Assign the price book entry to the OrderItem.
oi.PricebookEntryId = stdPriceBookEntry.id;

Reference:https://salesforce.stackexchange.com/questions/274205/writing-test-class-for-order-activate-error-required-fields-are-missing-pric

Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful. Thank you​​​​​​​
Ian Lin 439Ian Lin 439
No while calling the save method from my extension i am getting this error.my order as well as orderItem in my vf page are not getting inserted and this error is poping up.
ANUTEJANUTEJ (Salesforce Developers) 
Hi Ian,

Looks like there could be other validation rules or triggers that could be running you need to check if there are any and see-through that the required fields are not empty while inserting the record.

Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.  

Thanks.