This error " List has no rows for assignment to SObject" occurs if you try to put a value from list(that would return 1 record) into a defined variable(to accept a single value) and the list in reality does'nt return any value. This results in executing variablename =null;
Following example depicts the error " List has no rows for assignment to SObject".
Visualforce Page
Controller
In the statement,
conRec = [Select Name,id from contact where id=:'zzzzz' limit 1];
conRec = [Select Name,id from contact where id=:'zzzzz' limit 1];
Query doesnt return any record which throws the exception " List has no rows for assignment to SObject".
We can put such kind of code in try and catch and show user a desired message.
No comments:
Post a Comment