Tuesday, December 15, 2015

Illegal assignment from LIST<Account> to LIST<Account> at line in Apex Class

Whenever you have return Query on any object if it is returning more than one record then we will be using the List datatype to store that result .Here is the some interesting issue that I faced when I am assigning my results of type List<Account> to List<Account>

Public class AccountController
{
 List<Account> listAcc{get;set;}
 public AccountController()
 {
    listAcc = new List<Account>();
 listAcc = [Select id,name FROM Account ];
 }
}

When I am execute this class I am getting an error at line Query Illegal assignment from LIST<Account> to LIST<Account> at line in Salesforce Class.
Here I'm getting list of accounts from query and I am assigning that to List<Account> listAcc only but why still I getting this error.I searched for it so many places finally I got the solution(Thanks for the Jitendra who provided me the solution).

WorkAround:
In my organization somewhere I have created a class named "Account". That is why the compiler is not able to understand that it is standard Object Account or the class created in my org.Now I renamed my class to some other name now it's working perfectly.

3 comments:

  1. some times simple error are headache.

    ReplyDelete
  2. Thanks for the clear explanation. I faced the similar situation and it is solved now

    ReplyDelete