You need to sign in to do that
Don't have an account?

Apex Extension "Order By" not sorting OrderItems by UnitPrice in VF Page
Hello,
I'm new to VF & Apex and have been able to get by with most things doing my own research. I'm currently doing a project where I automate an order confirmation page using fields on the order object.
I know this may be somewhat of a simple problem, but the only roadblock I've come into, is being able to sort the items in my VF table by the unit price. I know of using controller extension SELECT... FROM... ORDER BY... but it doesn't seem to be working. Below is my extension & snippet of the VF table. Could someone please help me out or point me in the right direction for a solution? Thank you so much!
Controller Extension:
public class OrderProductExtension{
public List<OrderItem> getproducts(){
return products;
}
public OrderProductExtension(ApexPages.StandardController stdController){}
List<OrderItem> products =
[SELECT Quantity, PricebookEntry.Product2.Name, UnitPrice, TotalPrice FROM OrderItem
ORDER BY UnitPrice DESC];
}
VF Page Table:
<apex:pageBlock title="Line Items" >
<apex:pageBlockTable value="{!Order.OrderItems}" var="oi" >
<apex:column value="{!oi.Quantity}"/>
<apex:column value="{!oi.PricebookEntry.Product2.Name}"/>
<apex:column value="{!oi.UnitPrice}"/>
<apex:column value="{!oi.TotalPrice}"/>
</apex:pageBlockTable>
</apex:pageBlock>
I'm new to VF & Apex and have been able to get by with most things doing my own research. I'm currently doing a project where I automate an order confirmation page using fields on the order object.
I know this may be somewhat of a simple problem, but the only roadblock I've come into, is being able to sort the items in my VF table by the unit price. I know of using controller extension SELECT... FROM... ORDER BY... but it doesn't seem to be working. Below is my extension & snippet of the VF table. Could someone please help me out or point me in the right direction for a solution? Thank you so much!
Controller Extension:
public class OrderProductExtension{
public List<OrderItem> getproducts(){
return products;
}
public OrderProductExtension(ApexPages.StandardController stdController){}
List<OrderItem> products =
[SELECT Quantity, PricebookEntry.Product2.Name, UnitPrice, TotalPrice FROM OrderItem
ORDER BY UnitPrice DESC];
}
VF Page Table:
<apex:pageBlock title="Line Items" >
<apex:pageBlockTable value="{!Order.OrderItems}" var="oi" >
<apex:column value="{!oi.Quantity}"/>
<apex:column value="{!oi.PricebookEntry.Product2.Name}"/>
<apex:column value="{!oi.UnitPrice}"/>
<apex:column value="{!oi.TotalPrice}"/>
</apex:pageBlockTable>
</apex:pageBlock>
Guess you would like to show only the orderitems related to a particular order. If so, please update with below query,
products = [SELECT Quantity, PricebookEntry.Product2.Name, UnitPrice, TotalPrice FROM OrderItem where orderId =: stdController.getId() ORDER BY UnitPrice DESC];
All Answers
<apex:pageBlockTable value="{!Order.OrderItems}" var="oi" > in your VF page
with
<apex:pageBlockTable value="{!products}" var="oi" >
My thought that it is because there is no "WHERE condition" that will list only the items I have selected from my price book into the VF page. How would I be able to specify this?
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_readonly_context_pagelevel.htm
Guess you would like to show only the orderitems related to a particular order. If so, please update with below query,
products = [SELECT Quantity, PricebookEntry.Product2.Name, UnitPrice, TotalPrice FROM OrderItem where orderId =: stdController.getId() ORDER BY UnitPrice DESC];