function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Syed Aswan 5Syed Aswan 5 

Illegal assignment from List<Account> to List<Account> at line 6 column 9

Can anyone tell me what is the error in the following code, I'm getting the above error:
Public class AccountUtils
{
    List<Account> accountsByState (String Str)
    {
        List<Account> accList = new List<Account>();
        accList=[SELECT ID,name from Account where BillingState=:Str];
        return accList;
    }
}
Best Answer chosen by Syed Aswan 5
Amit Chaudhary 8Amit Chaudhary 8
Hi Syed Aswan 5,

You code look good to me. Can you please you have any apex class with Account Name if yes then please rename or delete that class and try again above code.

Please let us know if this will help you

Thanks
AMit Chaudhary

 

All Answers

Amit Chaudhary 8Amit Chaudhary 8
Hi Syed Aswan 5,

You code look good to me. Can you please you have any apex class with Account Name if yes then please rename or delete that class and try again above code.

Please let us know if this will help you

Thanks
AMit Chaudhary

 
This was selected as the best answer
DeepthiDeepthi (Salesforce Developers) 
Hi Syed,

In your organization somewhere you have created a class named "Account". Thats why the compiler is not able to understand that it is standard Object Account or the class created by you. Please rename your class, it will work.

Or you can assign your list with prefixing with "Schema"
 
List<Schema.Account> accList;
Try working on your class:
Public class AccountUtils
{
    List<Schema.Account> accountsByState (String Str)
    {
        List<Schema.Account> accList = new List<Schema.Account>();
        accList=[SELECT ID,name from Account where BillingState=:Str];
        return accList;
    }
}


Hope this helps you!
Best Regards,
Deepthi
Syed Aswan 5Syed Aswan 5
Hello, Amit Chaudhary 8.

Thanks it worked.
ishwar panjari 10ishwar panjari 10
Hi,
I have tried and its working fine. e.g:
AccountUtils ac=new AccountUtils();
List<Account> acList=ac.accountsByState('GenePoint');
System.debug('output is'+acList);

OUTPUT:
output is(Account:{Id=0012800000QvVY3AAN, Name=GenePoint})
 
ishwar panjari 10ishwar panjari 10
Just i have modified the access modifier for accessing this clas outside. and its worked
 
K S 77K S 77
If everything is all correct, at times it requires just to repoint to another playground without this class, check challenge and then point it back to original playground and recheck challenge, and it worked.