虽然查询返回行,但List没有用于分配给SObject错误的行

时间:2018-02-06 14:29:10

标签: salesforce visualforce apex soql

我对apex有点新意,我正在尝试使用我构建的自定义控制器在visualforce页面中显示selectList。

我得到一个" List没有用于分配给SObject的行#34;尝试预览visualforce页面时出错,但在开发人员控制台中运行查询会返回行。

这是我的页面:

<apex:page Controller="BpmIcountPayment">
<apex:form >
    <apex:selectList value="{!productsTitle}" multiselect="false">
        <apex:selectOptions value="{!ProductsLov}"></apex:selectOptions>
    </apex:selectList>
</apex:form>
</apex:page>

和我的控制员:

public class BpmIcountPayment{

    private final Account account;

    public String productsTitle {
      get { return 'products for sale'; }
      set;
    }

    public BpmIcountPayment() {
        account = [SELECT Id, Name, Site FROM Account
                   WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
    }

    public Account getAccount() {
        return account;
    }

    public List<SelectOption> getProductsLov() {
        List<SelectOption> products = new List<SelectOption>();
        List<Product2> productsList = [SELECT Id, Name, Family 
                                       FROM Product2 
                                       WHERE (Family = 'ShopProduct') 
                                       OR (Family = 'CourseParent') 
                                       OR (Family = 'SFCourseProgram')];

        for (Product2 currProduct : productsList) {
            products.add(new SelectOption(currProduct.Id, currProduct.Name));
        }

        return products;
    }
}

只是为了澄清我在getProductsLov()中提到的查询。

我的API版本是40,我在沙盒环境中工作。

1 个答案:

答案 0 :(得分:1)

不可能。如果你得到“list没有要分配给sObject的行”,则意味着你要分配给单个对象。这会消除QwtRasterData(除非您没有发布整个代码),因为您已分配给列表。

在解雇该查询之前,你在构造函数中使用Humo(u)和getProductsLov ...

您正在查看网址中传递了有效帐号ID的页面?该帐户对于您当前的用户是否可见?如果页面是特定于帐户的,请尝试使用System.debug(JSON.serializePretty(ApexPages.currentPage().getParameters()));(您必须先在apex中提供不同的构造函数)。这可以大大简化您的代码。

<apex:page standardController="Account" extensions="BpmIcountPayment">...
相关问题