function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Miranda L 2Miranda L 2 

I am getting error in visualforce page

Hello there,
I am getting the error after I press the button 
System.QueryException: List has no rows for assignment to SObject
Class.WizardCompController.<init>: line 269, column 1
please suggest me how to resolve it
 
AbhishekAbhishek (Salesforce Developers) 
QueryException: List has no rows for assignment to SObject. It means your SOQL didn't return any results. You can wrap it in a try/catch statement to handle this gracefully

For reference check this,

https://help.salesforce.com/articleView?id=000328824&type=1&mode=1


I hope you find the above information is helpful. If it does, please mark as Best Answer to help others too.

Thanks.
vishal-negandhivishal-negandhi

Hi Miranda, 

One good way to handle this is

Instead of doing this
Account abcAccound = [Select Id, Name FROM Account WHERE Name = 'abc'];

you'll end up hitting the exception that you're facing with above code if there are no records that are returned for your query

A better way to handle the above code is

List<Account> accountResult = [Select Id, Name FROM Account WHERE Name = 'abc'];
if(accountResult.size() > 0){
     // your logic here
}


Hope this helps.

Best,

Vishal