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
sf ostsf ost 

display pricebook products on visualforce page

I need to display products in Order object. We are using 'Order Products (Pricebook)' standard object which is in lookup with 'Orders'. But i am unable to find api name of 'Order Products' standard object to query them products selected from pricebook.

I need to show both "order details" and "products in order (Order Products)" details.

My contoller code. Working for only retriving orders. Not working for quering order products (Pricebook)
 
public with sharing class OrdersController {

    public List<Order> orderList {get;set;}
    
    public OrdersController(){
        orderList = new List<Order>();
    }
    
    public List<Order> getOrders(){
        return [SELECT OrderNumber, TotalAmount, Status (Select Product2Id, Product2.Name From PricebookEntry__r Where Product2Id =: productdet) FROM Order WHERE OwnerID=: UserInfo.getUserId()];
    }
 }
My VF code:
 
<apex:page controller="OrdersController" showHeader="false">

<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
    
jQuery.noConflict();
    
    jQuery(document).ready(function($) {
        
        $("#pnl_details").hide();
 
        $('#viewDetails').click(function () {
            if ($("#pnl_details").is(":hidden")) {
                $("#pnl_details").slideDown("slow");
                $("#viewDetails").html("Show Less Details");
                 return false;
            } else {
                $("#pnl_details").hide("slow");
                $("#viewDetails").html("Show More Details");
             return false;
            }
            });         
    });
</script>

  <apex:pageBlock >
  <!-- <apex:repeat value="{!Orders}" var="owd">
            ['{!owd.OrderNumber}','{!owd.TotalAmount}','{!owd.Status}']
</apex:repeat> -->
  <apex:pageBlockSection title="Orders" id="pnl_details" columns="1">
        <apex:pageBlockTable value="{!orders}" var="o">
      
            <!-- <apex:column headerValue="Order Number">
                <apex:commandLink action="{!URLFOR($Action.Order.View, o.id)}" value="{!o.OrderNumber}"/>
            </apex:column> -->
            <apex:column value="{!o.OrderNumber}"/>
            <apex:column value="{!o.TotalAmount}" />
            <apex:column value="{!o.Status}" />
            
      </apex:pageBlockTable>
  </apex:pageBlockSection>
<apex:pageBlockSection columns="1">
    <apex:relatedList list="Pricebook2 " />
</apex:pageBlockSection>
  </apex:pageBlock>

</apex:page>



help me in this.
 
~Onkar~Onkar
Hello.

This is Sample Query you can use to retrive Order Product and product infromation.

SELECT OrderItemNumber,Quantity,UnitPrice,PricebookEntry.Name FROM OrderItem

API name for Order Product is orderitem.


Hope this will resolve your problem.

~Onkar Kumar