简体   繁体   English

System.QueryException:列表有超过 1 行分配给 SObject

[英]System.QueryException: List has more than 1 row for assignment to SObject

  public void search ()
   {
    
        string searchquery='select Car_Name__c ,id  from car__c where Car_Name__c  like \'%'+ searchkey+'%\' Limit 20';
        sim=Database.query(searchquery);
        

   }

System.QueryException: List has more than 1 row for assignment to SObject Error is in expression '{:search}' in component apex:commandButton in page simpsons_vf01_car_show. System.QueryException:列表有超过 1 行分配给 SObject 错误在 simpsons_vf01_car_show 页面中组件 apex:commandButton 中的表达式“{:search}”中。 Class.Simpsons_Cl1_classCar:search, line 36, column 1 Class.Simpsons_Cl1_classCar:搜索,第 36 行,第 1 列

Presumably the value sim is of type Car__c .据推测,值sim的类型为Car__c You cannot assign the result of a query that returns anything other than exactly one record to a value whose type is an SObject.您不能将返回除一条记录之外的任何内容的查询结果分配给类型为 SObject 的值。 In particular, this does not make sense when you're performing a search query with a LIMIT 20 clause.特别是,当您使用LIMIT 20子句执行搜索查询时,这没有任何意义。

You should type your variable as a List<Car__c> .您应该将变量键入为List<Car__c>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Salesforce控制器扩展测试:System.QueryException:列表中没有可分配给SObject的行 - Salesforce Controller Extension Testing: System.QueryException: List has no rows for assignment to SObject System.QueryException:记录当前不可用 - System.QueryException: Record Currently Unavailable 获取 System.QueryException:第 1:40 行在字符“\”处没有可行的替代方案 - Getting System.QueryException: line 1:40 no viable alternative at character '\' 失败消息:“ System.QueryException:实体&#39;Lead&#39;上没有这样的列&#39;Address&#39;。I - Failure Message: "System.QueryException: No such column 'Address' on entity 'Lead'. I 列表中没有可分配给SObject Test类错误的行 - List has no rows for assignment to SObject Test class error 列表没有行分配给SObject错误,尽管查询返回了行 - List has no rows for assignment to SObject error although query returns rows 顶点测试日志出错:common.apex.runtime.impl.ExecutionException:List没有用于赋值给SObject的行“ - Error in apex test logs: common.apex.runtime.impl.ExecutionException: List has no rows for assignment to SObject" System.FinalException:SObject行不允许错误 - System.FinalException: SObject row does not allow errors 来自多态域的非法多态分配[SOBJECT:User,SOBJECT:Calendar] - Illegal polymorphic assignment from polymorphic domain [SOBJECT:User, SOBJECT:Calendar] System.sobjectexception:通过 soql 检索 sobject 行而不查询请求的字段:Asset.Product2 - System.sobjectexception: sobject row was retrieved via soql without querying the requested field: Asset.Product2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM