System.QueryException:列表没有要分配给SObject的行

问题描述

我想使用visualforce页面更新机会列表。在visualforce页面中,我想要更新金额,关闭日期和阶段。visulaforce页面应仅显示所有未解决的机会(阶段不等于已关闭的获胜和已关闭的损失)。>

任何人都可以帮助我解决此错误,并仅更新所有未解决的机会。

这是我的代码:

顶点

public class UpdateListofOppty {
    public Opportunity opportunities {get;set;} 
    public Id recId{get;set;}
    public UpdateListofOpporunity(ApexPages.StandardSetController sc){
    recId = ApexPages.CurrentPage().getParameters().get('id');
    opportunities = [SELECT Name,Amount,StageName FROM opportunity WHERE Id = :recId AND StageName NOT IN ('Closed Lost','Closed Won')];
    }

    public Opportunity getOpptyDetail(){
        return opportunities;
    }

    public PageReference Save() {
        try{
        update(opportunities);
        }
        catch(System.DmlException e){
        ApexPages.addMessages(e);
        return null;
    }
        PageReference view = new ApexPages.StandardController(opportunities).view();
         return (view);
    }
}

VF页面

<apex:page standardController="Opportunity" extensions="UpdateListofOppty" recordSetVar="opportunities" tabStyle="Opportunity" sidebar="false">
    <apex:form >
        <apex:pageBlock >
            <apex:pageMessages />
            <apex:pageBlockButtons >
                <apex:commandButton value="Save" action="{!save}"/>
            </apex:pageBlockButtons>
            <apex:pageBlockTable value="{!opportunities}" var="opp">
                <apex:column value="{!opp.name}"/>
                <apex:column headerValue="Amount">
                    <apex:inputField value="{!opp.Amount}"/>
                </apex:column>
                <apex:column headerValue="Close Date">
                    <apex:inputField value="{!opp.CloseDate}"/>
                </apex:column>
                <apex:column headerValue="Stage">
                    <apex:inputField value="{!opp.stageName}"/>
                </apex:column>
            </apex:pageBlockTable>      
        </apex:pageBlock>
    </apex:form>
</apex:page>

错误:

System.QueryException:列表中没有可分配给SObject的行

此行显示错误:

opportunities = [SELECT Name,'Closed Won')];

解决方法

我怀疑您的id参数没有通过,因此为空。查询机会WHERE Id = null将始终返回零结果。也许它正在通过,但没有用。如果您拥有StandardSetController,则页面URL中的ID值可能会用作过滤器ID(列表视图),而不是任何特定记录的ID。意味着查询仍将返回0行。

您想做什么?尽管此列表可以非常快速地增长,但也许只删除部分条件会有所帮助。您可能想在查询中放入LIMIT语句,或阅读有关StandardSetController和分页的信息。

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...