Home SALESFORCEAPEX Salesforce – List has no rows for assignment to SObject

Salesforce – List has no rows for assignment to SObject

if you using following code in Apex and Error should throw like “List has no rows for assignment to SObject”.

Account a = [Select name from acoount where id =: strId];

Try to avoid the error following code in you Apex.

List<Account> lstAccount = [Select Id, name from acoount where id =: strId];

if (lstAccount.size() > 0) {
    String Name = lstAccount[0].Name;
}

You may also like

Leave a Comment