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
ReemaReema 

What is wrong with the query?

List<Product2> listOfProducts = [SELECT Id, Name, Description, IsActive, Parent_Product__c, Account__c ,
                                   (SELECT Id, Product2Id, Quantity FROM OrderItem) FROM Product2 
                                  WHERE Account__c = 'XYZ'];

ERROR at Row:2:Column:74
Didn't understand relationship 'OrderItem' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.
nilesh walkenilesh walke
Hi reema 
 If i am not rong the OrderItem and The Product2 both are custom fields !?
if yes you need  to use that like OrderItems__c ,Product2__c  try like this it will  work ( id you are uding the child to parent relationship  you should use the label name in this case it might be  OrderItems__c  for sub class only) other else  query  is all correct check the fields too
ReemaReema
Hi nilesh,
They are standard objects.
nilesh walkenilesh walke
 hello
Reema please get info about Sojects you will get the answer in it your query id correct just chect the child name once 
Suraj Tripathi 47Suraj Tripathi 47
Hi Reema,

This error is getting in your code because there is no relationship between product2 and orderitem. If you want to get the orderItem then check this query:-
List<pricebookentry> pbe=[SELECT id, Product2.Name, (select Id from OrderItems) FROM PricebookEntry];

In case you find any other issue please mention. 
If you find your Solution then mark this as the best answer. 

Thanks and Regards
Suraj Tripathi.
ReemaReema
Product and OrderProduct  are standard objects and they have a lookup where Product is the Parent. I got those Field names from Query Editor, so they can't be wrong either.
Jake Backues 34Jake Backues 34
I just wanted to put this somewhere on the internet. To give access to the OrderItem object (the standard object API Name for Order Products) you must give access to Orders, Pricebooks and Product2s with the crud necessary.