我已经在我的visualforce页面添加了一个标准控制器(“OrderItem”)和一个扩展。我试图根据页面的订单记录ID来查看OrderItem的详细信息。但我一直收到错误消息“ID值对于visualforce标准控制器无效”。
因为我想用我的visualforce页面覆盖"Order Products“中的"EditProducts”按钮。我必须为"OrderItem“使用standardController。订购产品的接口名称是什么?
请帮帮忙。谢谢!
<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';
}}
发布于 2020-08-17 18:45:23
你需要作弊一点。选项1是使按钮按订单,而不是按订单项目。它将显示在错误的位置,但您应该能够隐藏旧按钮和训练用户。然后,订单id将被传递,它将正常工作。尽管如此,仍然需要standardController="Order"。
选项2有点混乱。像<apex:page standardController="OrderItem" recordSetVar="records"这样的内容会表明您计划将此页面用于多个项目,而不只是一个。也许你听说过StandardSetController?但是你没有订单id (好吧,如果有已有的行,你可以这样做,但是如果还没有添加行怎么办)。看看是否可以将按钮重写为URL (/apex/MyPageName?id={!Order.Id})类型,而不是按钮类型。
https://stackoverflow.com/questions/63434571
复制相似问题