[英]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.