+ Start a Discussion
Abhilash Mishra 13Abhilash Mishra 13 

gettting all the products Of an order by SOQL

I want to get all the product associated with an order. like shown in order product related list. how can i do This.
Need urgent help thanks in advance.
Best Answer chosen by Abhilash Mishra 13
sachin kadian 5sachin kadian 5
Here is the full code
List<String> productNames = new List<String>();
for(order ord:[SELECT Id,name,(select Id,
       OrderId,   
       OrderItemNumber,
       PricebookEntry.Product2.Name,
       PricebookEntry.Product2.id,
       Quantity,
       UnitPrice
       FROM OrderItems ) from order where id='801280000000PTy']){
           for(OrderItem oi : ord.orderItems){
               productNames.add(oi.PricebookEntry.Product2.name);
           }    
}
System.debug(productNames);