-1
  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: Class.Simpsons_Cl1_classCar.search: line 36, column 1

David Reed
  • 2,522
  • 2
  • 16
  • 16
Harsh
  • 1
  • 1
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jan 04 '22 at 19:42

1 Answers1

0

Presumably the value sim is of type 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. In particular, this does not make sense when you're performing a search query with a LIMIT 20 clause.

You should type your variable as a List<Car__c>.

David Reed
  • 2,522
  • 2
  • 16
  • 16