【问题标题】:Get Order Products based Order ID获取基于订单产品的订单 ID
【发布时间】: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


    【解决方案1】:

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

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

    【讨论】:

    • 感谢您的回答。我将研究选项 1。此外,我相信“OrderItems”没有标准列表,因此使用 recordSetVar 会在 VF 页面上出错。
    猜你喜欢
    • 2017-09-25
    • 1970-01-01
    • 1970-01-01
    • 2021-12-06
    • 1970-01-01
    • 1970-01-01
    • 2021-04-23
    • 2022-07-16
    • 1970-01-01
    相关资源
    最近更新 更多