Skip to main content
Paddy R 님이 #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개
  1. 2014년 3월 19일 오전 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) { ....... }