+ Start a Discussion
sf ostsf ost 

Display "Order & Order Products" on visualforce page

Hi guys,

Am new to salesforce. I need to display Order and Order products on a vf page based on user logged-in. Both are standard objects. Order and Order products are in lookup. Help me regarding this...
Best Answer chosen by sf ost
Ravi Dutt SharmaRavi Dutt Sharma
List<OrderItem > orderItemList = [SELECT OrderId FROM OrderItem WHERE OrderId IN:orderSet];

You need to store all the order id's that you get from query1 into a set named orderSet.

All Answers

Ravi Dutt SharmaRavi Dutt Sharma
Based on logged in user means? Do you want to only display records whose owner is logged in user?
sf ostsf ost
exactly. I need to display orders placed by community user. Simply Orders history..( ex: amazon orders history)
Ravi Dutt SharmaRavi Dutt Sharma
You can use below code as reference and built your code upon it.

VF Page : 
 
<apex:page controller="OrdersController">
  <apex:pageBlock >
      <apex:pageBlockTable value="{!orders}" var="order">
            <apex:column value="{!order.OrderNumber}" />
      </apex:pageBlockTable>
  </apex:pageBlock>
</apex:page>

Apex Controller :
 
public with sharing class OrdersController {

    public List<Order> orderList {get;set;}
    
    public OrdersController(){
        orderList = new List<Order>();
    }
    
    public List<Order> getOrders(){
        return [SELECT OrderNumber FROM Order WHERE OwnerID=: UserInfo.getUserId()];
    }
}

 
sf ostsf ost
also i need to display products in Order. We are using 'Order Products' standard object which is in lookup with 'Orders'. But i am unable to find api name of 'Order Products' standard object to query them.

Help me in this.
Ravi Dutt SharmaRavi Dutt Sharma
List<OrderItem > orderItemList = [SELECT OrderId FROM OrderItem WHERE OrderId IN:orderSet];

You need to store all the order id's that you get from query1 into a set named orderSet.
This was selected as the best answer
EldonEldon
API name of 'Order Products' is 'OrderItem'.