【发布时间】:2020-08-16 08:03:55
【问题描述】:
我在我的 visualforce 页面中添加了一个标准控制器(“OrderItem”)和一个扩展。我正在尝试根据页面的订单记录 ID 查看 OrderItem 详细信息。但我不断收到错误“Id 值不是对 OrderItem 标准控制器有效”。
因为我想用我的 visualforce 页面覆盖“订购产品”中的“编辑产品”按钮。我必须为“OrderItem”使用标准控制器。 “订购产品”的 API 名称是什么
请帮忙。谢谢!
<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>
我的自定义扩展:
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';
}
}
【问题讨论】:
标签: salesforce apex visualforce