Sunday 26 April 2020

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 AccountSearch
{
 List<Account> listAcc{get;set;}
 public AccountSearch()
 {
    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.

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.