我在我的visualforce页面和扩展中添加了一个standardcontroller(“ OrderItem)。我试图根据该页面的Order记录ID查看OrderItem详细信息。但是我一直收到错误消息” Id value not not对OrderItem标准控制器有效”。
因为我想用我的visualforce页面覆盖“订购产品”中的“ EditProducts”按钮。我必须对“ OrderItem”使用standardController。 “订购产品”的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';
}
}
答案 0 :(得分:1)
您将需要作弊。
选项1是在“订单”而不是“订单项”上创建按钮。它会显示在错误的位置,但是您应该可以隐藏旧按钮并培训用户。然后订单ID将被传递,它将正常运行。 standardController="Order"
还是需要的。
选项2有点混乱。类似<apex:page standardController="OrderItem" recordSetVar="records"
之类的内容表示您打算将此页面用于多个项目,而不仅仅是一个项目。也许您听说过StandardSetController?但是,那么您就没有订单ID(好吧,如果已有行,您可以这样做,但是如果没有添加该行怎么办)。查看是否可以使按钮作为URL类型(/apex/MyPageName?id={!Order.Id}
)而不是按钮类型。