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
venkyyyvenkyyy 

In what scenarios the following error will come??

Hi Experts,
In what scenarios this ( "List has no rows for assignment to SObject" ) error will come ??
Please give me explenation,,

Thanks in advance.
 
Akhil AnilAkhil Anil
This error comes up when the SOQL query you fired didn't find any records that matched the conditions in your query.
RAM AnisettiRAM Anisetti
Hi,

Take example like 
=>you need to update accounts names to 'Venky' from who is already having account names as 'Ram'

for this
1) using SOQL ,get all the accounts having names Ram in entire Org.
2)Using For loop ,update the above list 

List<Account>acclist=[Select Name from Account where Name like '%Ram%' ];
for(Account a:acclist){
  a.Name='Venki';
}
update acclist;

The error "List has no rows for assignment to SObject" will occur in the case of no record existing having name 'RAM'.

i.e,acclist is null,but u are trying to update Null List.