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
José Luis Ingelmo Zorrilla 10José Luis Ingelmo Zorrilla 10 

How can I get the Order Product information into my VF page?

Hello,

I'm building a VF page which retrieves info from the Order standard object and I have some difficulties to retrieve the information from the Order Products. How can I achieve it?

It seems to me there is no specific standard field in the Order standard object, but searching on the Internet it seems the Order Products are controlled by OrderItem but I don't understand how to retrieve the information to my VF page.



Also I need to create it for my VF page, not just for one specific order (I mean, one order ID), but also for every order it's registered into the system.



Thanks in advance.
Rahul_kumar123Rahul_kumar123
Hi Jose,
 
List<OrderItem > orderItemList = [SELECT OrderId FROM OrderItem WHERE OrderId IN:orderSet];
I hope it will be helpful.

Best Regards
RahulKumar
 
José Luis Ingelmo Zorrilla 10José Luis Ingelmo Zorrilla 10
Thanks, but if I use the custom OrdersController into my <apex:page> , can I use the standardController="Order" value too? Because I need to retrieve information for my VF page from the Order controller to get the contact information (name, e-mail, etc.) too.
Ramssf70Ramssf70
Hi Jose,
You can use following code to get the order item information

visuval force page
 
<apex:page controller ="orderitemcontroller">

<apex:form>
<apex:pageblock>
<apex:pageblocktable value="{!orderItemList}"  var="ord">
<apex:column value="{!ord.Description}">
<apex:column value="{!ord.Product2Id}">
<apex:column value="{!ord.Quantity}">
</apex:pageblocktable>
</apex:pageblock>
</apex:form>
</apex:page>

controller
 
public class orderitemcontroller
{


public List<orderitem> orderItemList{get;set;}


public void getdata()
{
List<order> orderset =[select id from order limit 5];
List<OrderItem > orderItemList = [SELECT Description,Product2Id,Quantity ,OrderId FROM OrderItem WHERE OrderId IN:orderSet];
}



}


Thank you
 
José Luis Ingelmo Zorrilla 10José Luis Ingelmo Zorrilla 10

Many thanks for your replies.

I've done the following:

First of all, I create an Apex Class exactly as Ramssf70 said. However when I insert the code part in my VF page, I get an "Error: Unknown constructor 'orderitemcontroller.orderitemcontroller(ApexPages.StandardController controller)'"

Part of my VF code is:

<apex:page StandardController="Order" extensions="orderitemcontroller" renderAs="pdf">


    <apex:form >

             <apex:pageblock>
                     <apex:pageblocktable value="{!orderItemList}" var="ord">
                                 <apex:column value="{!ord.Description}" />
                                 <apex:column value="{!ord.Product2Id}" />
                                 <apex:column value="{!ord.Quantity}" />
                     </apex:pageblocktable>
            </apex:pageblock>

    </apex:form >


</apex:page>
As I said before, I need the StandardController="Order" to retrive information regards contact (name, e-mail, etc.)
Ramssf70Ramssf70
Hi Jose,

try this bellow code 

visuval force page
 
<apex:page StandardController="Order" extensions="orderitemcontroller" renderAs="pdf">


    <apex:form >

             <apex:pageblock>
                     <apex:pageblocktable value="{!orderItemList}" var="ord">
                                 <apex:column value="{!ord.Description}" />
                                 <apex:column value="{!ord.Product2Id}" />
                                 <apex:column value="{!ord.Quantity}" />
                     </apex:pageblocktable>
            </apex:pageblock>

    </apex:form >


</apex:page>

Controller

public class orderitemcontroller
{
  public List<orderitem> orderItemList{get;set;}
  
    public orderitemcontroller(ApexPages.StandardController controller) 
    {
       List<order> orderset =[select id from order limit 5];
      List<OrderItem > orderItemList = [SELECT Description,Product2Id,Quantity ,OrderId FROM OrderItem WHERE OrderId IN:orderSet];
    }

}

if you have any queries please let me know i can try to help you 

Thank you
Jose Luis Ingelmo 5Jose Luis Ingelmo 5

Ramssf70, after creating a new Apex Class with you Controller code and insert your VF page code into my VF page, I get the following error when trying to save my VF page: "Error: Unknown property 'OrderStandardController.orderItemList'".

In order to eliminate other possibly causes of the error from my VF page code, I've created a new VF page with your VF page code and nothing happens when I pass the ID through the URL. It's supposed to show only the Order Products for the ID of the order, isn't it?

Thanks for your help and kind regards.