Skip to main content
Paddy R ha preguntado en #Customer Service
List<Account>  acc = [select id,name from Account where Name='abc']; // I am getting Line has no rows for assignment when no record returned from query..

 

If(acc.size()>0)

 

{

 

code

 

}

 

Any suggestion...
4 respuestas
  1. 19 mar 2014, 10:13
    You can also use a different syntax for initializing your List so you don't have to put try/catch blocks around things:

     

    List<Account> acc = new List<Account>([select ......]);

     

    This will initialize the List, and optionally populate it with records if the SELECT returns records.  Otherwise, you have a valid List with no records and can safely check the size:

     

    if (acc.size() > 0) { ....... }