首页 > 解决方案 > 获取基于订单产品的订单 ID

问题描述

我已在我的 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>

</apex:page>

我的自定义扩展:

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';
}

}

标签: salesforceapexvisualforce

解决方案


你需要作弊一点。选项 1 是在 Order 上制作按钮,而不是 Order Items。它会显示在错误的位置,但您应该能够隐藏旧按钮并培训用户。然后订单ID将被传递,它会正常工作。虽然standardController="Order"需要。

选项2有点混乱。类似的东西<apex:page standardController="OrderItem" recordSetVar="records"表明您计划将此页面用于多个项目,而不仅仅是一个。也许您听说过 StandardSetController?但是您没有订单 ID(好吧,如果有现有的行,您可以这样做,但如果还没有添加怎么办)。看看您是否可以将按钮覆盖为类型 URL ( /apex/MyPageName?id={!Order.Id}),而不是类型按钮。


推荐阅读