I have added a standardcontroller ("OrderItem) to my visualforce page and also an extension. I am trying to view the OrderItem details based on the Order record ID of the page. But I keep getting the error "Id value is not valid for the OrderItem standard controller".
Because I want to override the "EditProducts" button in "Order Products" with my visualforce page. I must use a standardController for "OrderItem". Which is the API name for "Order Products"
Please help. Thank you!
<apex:page standardController="OrderItem" extensions="OrderProductExtension" lightningStylesheets="true">
<apex:form>
<apex:pageBlock id="products_list" title="Order Products">
<apex:pageBlockTable value="{! Products}" var="Oi" >
<apex:column value="{! Oi.PricebookEntry.Product2.Name}">
<apex:facet name="header">
<apex:commandLink action="{! sortByName}" reRender="products_list">
<apex:outputText value="{! $ObjectType.OrderItem.Fields.Product2Id.Label}"/>
</apex:commandLink>
</apex:facet>
</apex:column>
<apex:column value="{! Oi.Quantity}">
<apex:facet name="header">
<apex:commandLink action="{! sortByQuantity}" reRender="products_list">
<apex:outputText value="{! $ObjectType.OrderItem.Fields.Quantity.Label}"/>
</apex:commandLink>
</apex:facet>
</apex:column>
<apex:column value="{! Oi.UnitPrice}">
<apex:facet name="header">
<apex:commandLink action="{! sortByUnitPrice}" reRender="products_list">
<apex:outputText value="{! $ObjectType.OrderItem.Fields.UnitPrice.Label}"/>
</apex:commandLink>
</apex:facet>
</apex:column>
<apex:column value="{! Oi.TotalPrice}">
<apex:facet name="header">
<apex:commandLink action="{! sortByTotalPrice}" reRender="products_list">
<apex:outputText value="{! $ObjectType.OrderItem.Fields.TotalPrice.Label}"/>
</apex:commandLink>
</apex:facet>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
my custom extension:
public class OrderProductExtension{
private String sortOrder = 'TotalPrice';
private String currentId;
public OrderProductExtension(ApexPages.StandardController stdController){
this.currentId = stdController.getId();
}
public List<OrderItem> getProducts(){
List<OrderItem> products = Database.query('SELECT Quantity, PricebookEntry.Product2.Name, UnitPrice, TotalPrice FROM OrderItem WHERE' +
' orderId =: currentId ORDER BY ' + sortOrder + ' ASC');
return products;
}
public void sortByName(){
this.sortOrder = 'PricebookEntry.Product2.Name';
}
public void sortByQuantity(){
this.sortOrder = 'Quantity';
}
public void sortByUnitPrice(){
this.sortOrder = 'UnitPrice';
}
public void sortbyTotalPrice(){
this.sortOrder = 'TotalPrice';
}
}