How to Fix ‘Illegal assignment from List to List Exception’ in Salesforce?

How to Fix ‘Illegal assignment from List to List Exception’ in Salesforce

We cannot create a class with the names Account, Contact, Opportunity,Case,Task etc. These are Standard object names. So, they are reserved keywords in Salesforce.


Sample Code for this Exception:
public class Account {
    public static List<Account> Accountlist(){
        List<Account> acclst = new List<Account>();
        acclst = [ SELECT Id, Email, Name FROM ACCOUNT LIMIT 5 ];
        return acclst;
    }
}

Exception:
Illegal assignment from List<Account> to List<Account>

Solution:
​​​​​​​Change the Class name to resolve this issue.

Follow Us

Posted By : Sudeer Kamat Date :

view_module Related

label Labels

Comments 0