Salesforce 虽然查询返回行,但列表中没有要分配给SObject错误的行
我对apex有点陌生,我正在尝试使用我构建的自定义控制器在visualforce页面中显示selectList 我在尝试预览visualforce页面时遇到“List has no rows for assignment to SObject”错误,但在开发人员控制台中运行查询时,会返回这些行 这是我的页面:Salesforce 虽然查询返回行,但列表中没有要分配给SObject错误的行,salesforce,visualforce,apex,soql,Salesforce,Visualforce,Apex,Soql,我对apex有点陌生,我正在尝试使用我构建的自定义控制器在visualforce页面中显示selectList 我在尝试预览visualforce页面时遇到“List has no rows for assignment to SObject”错误,但在开发人员控制台中运行查询时,会返回这些行 这是我的页面: <apex:page Controller="BpmIcountPayment"> <apex:form > <apex:selectList val
<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;
}
}
公共类BpmIcountPayment{
私人最终账户;
公共字符串{
获取{退货'待售产品';}
设置
}
公共BpmIcountPayment(){
account=[从account中选择Id、名称、站点
其中Id=:ApexPages.currentPage().getParameters().get('Id');
}
公共帐户getAccount(){
返回帐户;
}
公共列表getProductsLov(){
列表产品=新列表();
列表产品列表=[选择Id、名称、系列
来自产品2
其中(系列=‘ShopProduct’)
或(家庭='CourseParent')
或(Family='sfourseprogram');
对于(产品2当前产品:产品列表){
添加(新选择选项(currProduct.Id,currProduct.Name));
}
退货产品;
}
}
为了澄清我所指的查询是getProductsLov()
中的查询
我的API版本是40,我在沙箱环境中工作。不可能。若您得到“列表中并没有要分配给sObject的行”,则表示您正在分配给单个对象。这消除了
getProductsLov
(除非您没有发布整个代码),因为您在那里分配了一个列表
Humo(u)rme和System.debug(JSON.serializePretty(ApexPages.currentPage().getParameters())在启动该查询之前,请在构造函数中键入code>
您正在使用URL中传递的有效帐户Id查看页面?您的当前用户是否可以看到该帐户?如果页面是特定于帐户的,请尝试使用…
(您必须首先在apex中提供不同的构造函数)。这可以大大简化您的代码
public BpmIcountPayment(ApexPages.StandardController sc){
if(String.isBlank(sc.getId()){
System.debug('you screwed up passing the valid acc id');
} else {
acc = (Account) sc.getRecord();
}
}
你是对的!将有效的“id”参数添加到url后,页面将正确显示。非常感谢。