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
Kurt AlmeidaKurt Almeida 

Illegal assignment from LIST<Account> to LIST<Account>

I am receivin this general error.
Error(s) occurred while submitting the page. The error details are:
An exception was encountered when attempting to populate default value: (System.TypeException)Illegal assignment from List<Account> to Account

This is in our sandbox environment. We were able to use our sandbox without any issues a few days ago. We didn't make any change to our code. Today, we received this error. We ran a debug log and couldnt find anything either. What is going on? 
Best Answer chosen by Kurt Almeida
PawanKumarPawanKumar
Hi Kurt,
You will get this when you are expectng n result from SOQL, but it is giving more than one record.

e.g. 
Account queriedAccount = [Select Id from Account Limit 1];

The above will work fine always as you are limiting return record to 1.

But If you remove limit 1 from SOQL as shown in below SOQL query, then you query will return List<Account> instead single Account record;  this time you will get the same error what you are getting currently.
Account queriedAccount = [Select Id from Account]; // to avoid such error we should use list always as below.

// best practise
List<Account> queriedAccount = [Select Id from Account];// this will never throw such error.

Please let me know if it helps you.

Regards,
Pawan Kumar

All Answers

Lucas Duque 9Lucas Duque 9
Could you post the page's controller code ? For more details...
Kurt AlmeidaKurt Almeida
This is what happened when we compiled All Classes in our Sandbox environment. Any ideas as to what happened to our environment or how to fix this?
 
Compilation Complete
Compilation Errors found:
AccountRedirectController: line 6, column 9: Incompatible types since an instance of SObject is never an instance of Account
AccountRedirectController: line 16, column 29: Variable does not exist: Id
AccountRedirectController: line 20, column 106: Variable does not exist: Id
AccountRedirectController: line 23, column 38: Variable does not exist: Id
BillingAccountManager: line 54, column 22: Variable does not exist: Z_TestFactory
BillingAccountManager: line 56, column 42: Variable does not exist: Id
DemoEventEditorControllerTest: line 14, column 17: Invalid constructor syntax, name=value pairs can only be used for SObjects: Account
DemoEventEditorControllerTest: line 15, column 3: DML requires SObject or SObject list type: Account
DemoEventEditorControllerTest: line 18, column 23: Variable does not exist: Id
Dummy: line 1, column 14: Class Dummy must implement the method: void Database.Batchable<SObject>.execute(Database.BatchableContext, List<SObject>)
Dummy: line 7, column 13: global methods do not support parameter type of List<Account>
Dummytest: line 6, column 13: Invalid constructor syntax, name=value pairs can only be used for SObjects: Account
Dummytest: line 7, column 1: DML requires SObject or SObject list type: Account
MakeRefund: line 55, column 22: Variable does not exist: Z_TestFactory
MakeRefund: line 57, column 42: Variable does not exist: Id
QuoteTestClass: line 59, column 21: Variable does not exist: Name
QuoteTestClass: line 60, column 21: Variable does not exist: BillingCountry
QuoteTestClass: line 61, column 21: Variable does not exist: ShippingCountry
QuoteTestClass: line 62, column 21: Variable does not exist: BillingState
QuoteTestClass: line 63, column 21: Variable does not exist: ShippingState
QuoteTestClass: line 65, column 13: DML requires SObject or SObject list type: Account
QuoteTestClass: line 84, column 41: Variable does not exist: Id
QuoteTestClass: line 99, column 37: Variable does not exist: Id
TCVTestClass: line 50, column 57: Variable does not exist: Id
TCVTestClass: line 51, column 57: Variable does not exist: Id
TCVTestClass: line 52, column 62: Variable does not exist: Id
TCVTestClass: line 53, column 63: Variable does not exist: Id
TCVTestClass: line 60, column 57: Variable does not exist: id
TCVTestClass: line 76, column 47: Variable does not exist: Id
TCVTestClass: line 87, column 46: Variable does not exist: Id
testEditCard: line 28, column 51: Constructor not defined: [ApexPages.StandardController].<Constructor>(Account)
z_AccountCustomFieldsUpdateTest: line 42, column 62: Variable does not exist: Id
z_AccountCustomFieldsUpdateTest: line 43, column 74: Variable does not exist: Id
z_AccountCustomFieldsUpdateTest: line 60, column 62: Variable does not exist: Id
z_AccountCustomFieldsUpdateTest: line 61, column 74: Variable does not exist: Id
z_AccountCustomFieldsUpdateTest: line 80, column 17: Variable does not exist: Name
z_AccountCustomFieldsUpdateTest: line 81, column 17: Variable does not exist: Industry
z_AccountCustomFieldsUpdateTest: line 82, column 17: Variable does not exist: Industry_Category__c
z_AccountCustomFieldsUpdateTest: line 83, column 17: Variable does not exist: AccountSource
z_AccountCustomFieldsUpdateTest: line 84, column 17: Variable does not exist: type
z_AccountCustomFieldsUpdateTest: line 85, column 17: Variable does not exist: Status__c
z_AccountCustomFieldsUpdateTest: line 88, column 36: Variable does not exist: Id
z_AccountCustomFieldsUpdateTest: line 88, column 18: Variable does not exist: ParentId
z_AccountCustomFieldsUpdateTest: line 91, column 10: DML requires SObject or SObject list type: Account
z_AccountCustomFieldsUpdateTest: line 114, column 38: Variable does not exist: Id
z_AccountCustomFieldsUpdateTest: line 136, column 24: Variable does not exist: Id
z_AccountCustomFieldsUpdateTest: line 156, column 47: Variable does not exist: Id
Z_CreateQuote_DefaultValuePluginTest: line 42, column 62: Variable does not exist: Id
Z_CreateQuote_DefaultValuePluginTest: line 66, column 62: Variable does not exist: Id
Z_CreateQuote_DefaultValuePluginTest: line 91, column 62: Variable does not exist: Id
Z_CreateQuote_DefaultValuePluginTest: line 116, column 35: Variable does not exist: Id
Z_CreateQuote_DefaultValuePluginTest: line 146, column 31: Variable does not exist: Id
Z_CreateQuote_DefaultValuePluginTest: line 203, column 47: Variable does not exist: Id
Z_CreateQuote_DefaultValuePluginTest: line 220, column 17: Variable does not exist: Name
Z_CreateQuote_DefaultValuePluginTest: line 221, column 17: Variable does not exist: Industry
Z_CreateQuote_DefaultValuePluginTest: line 222, column 17: Variable does not exist: Industry_Category__c
Z_CreateQuote_DefaultValuePluginTest: line 223, column 17: Variable does not exist: AccountSource
Z_CreateQuote_DefaultValuePluginTest: line 224, column 17: Variable does not exist: type
Z_CreateQuote_DefaultValuePluginTest: line 225, column 17: Variable does not exist: Status__c
Z_CreateQuote_DefaultValuePluginTest: line 228, column 36: Variable does not exist: Id
Z_CreateQuote_DefaultValuePluginTest: line 228, column 18: Variable does not exist: ParentId
Z_CreateQuote_DefaultValuePluginTest: line 231, column 10: DML requires SObject or SObject list type: Account
Z_CreateQuote_DefaultValuePluginTest: line 248, column 24: Variable does not exist: Id
z_DefaultValuesController: line 38, column 8: Illegal assignment from List<Account> to Account
z_DefaultValuesControllerTest: line 11, column 58: Variable does not exist: Id
z_DefaultValuesControllerTest: line 12, column 62: Variable does not exist: Id
z_DefaultValuesControllerTest: line 34, column 58: Variable does not exist: Id
z_DefaultValuesControllerTest: line 35, column 62: Variable does not exist: Id
z_DefaultValuesControllerTest: line 72, column 53: Variable does not exist: Id
z_DefaultValuesControllerTest: line 89, column 17: Variable does not exist: Name
z_DefaultValuesControllerTest: line 90, column 17: Variable does not exist: Industry
z_DefaultValuesControllerTest: line 91, column 17: Variable does not exist: Industry_Category__c
z_DefaultValuesControllerTest: line 92, column 17: Variable does not exist: AccountSource
z_DefaultValuesControllerTest: line 93, column 17: Variable does not exist: type
z_DefaultValuesControllerTest: line 94, column 17: Variable does not exist: Status__c
z_DefaultValuesControllerTest: line 97, column 39: Variable does not exist: Id
z_DefaultValuesControllerTest: line 97, column 21: Variable does not exist: ParentId
z_DefaultValuesControllerTest: line 100, column 13: DML requires SObject or SObject list type: Account
z_DefaultValuesControllerTest: line 114, column 41: Variable does not exist: Id
z_DefaultValuesControllerTest: line 130, column 33: Variable does not exist: Id
Z_TestFactoryV2: line 331, column 17: Variable does not exist: Name
Z_TestFactoryV2: line 332, column 17: Variable does not exist: Industry
Z_TestFactoryV2: line 333, column 17: Variable does not exist: Industry_Category__c
Z_TestFactoryV2: line 334, column 17: Variable does not exist: AccountSource
Z_TestFactoryV2: line 335, column 17: Variable does not exist: type
Z_TestFactoryV2: line 336, column 17: Variable does not exist: Status__c
Z_TestFactoryV2: line 338, column 9: DML requires SObject or SObject list type: Account
Z_TestFactoryV2: line 358, column 41: Variable does not exist: Id
Z_TestFactoryV2: line 388, column 41: Variable does not exist: Id
Z_TestFactoryV2: line 425, column 49: Variable does not exist: Id
Z_TestFactoryV2: line 452, column 49: Variable does not exist: Id
Z_TestFactoryV2: line 472, column 37: Variable does not exist: Id
Z_TestFactoryV2: line 614, column 37: Variable does not exist: Id
Z_TestFactoryV2: line 620, column 47: Variable does not exist: Id
Z_VirtualSendToZBillingTest: line 46, column 53: Variable does not exist: Id
Z_VirtualSendToZBillingTest: line 47, column 53: Variable does not exist: Id
Z_VirtualSendToZBillingTest: line 57, column 42: Variable does not exist: Id
Z_VirtualSendToZBillingTest: line 85, column 17: Variable does not exist: Name
Z_VirtualSendToZBillingTest: line 86, column 17: Variable does not exist: BillingState
Z_VirtualSendToZBillingTest: line 87, column 17: Variable does not exist: BillingStreet
Z_VirtualSendToZBillingTest: line 88, column 17: Variable does not exist: BillingCity
Z_VirtualSendToZBillingTest: line 89, column 17: Variable does not exist: BillingCountry
Z_VirtualSendToZBillingTest: line 90, column 17: Variable does not exist: BillingPostalCode
Z_VirtualSendToZBillingTest: line 91, column 17: Variable does not exist: ShippingStreet
Z_VirtualSendToZBillingTest: line 92, column 17: Variable does not exist: ShippingCity
Z_VirtualSendToZBillingTest: line 93, column 17: Variable does not exist: ShippingCountry
Z_VirtualSendToZBillingTest: line 94, column 17: Variable does not exist: ShippingPostalCode
Z_VirtualSendToZBillingTest: line 95, column 17: Variable does not exist: ShippingState
Z_VirtualSendToZBillingTest: line 97, column 9: DML requires SObject or SObject list type: Account
Z_VirtualSendToZBillingTest: line 130, column 33: Variable does not exist: Id
ZuoraNewContractController: line 49, column 9: Illegal assignment from List<Account> to Account
ZuoraNewContractController: line 53, column 26: Variable does not exist: Name
ZuoraNewContractController: line 54, column 29: Variable does not exist: Website
ZuoraNewContractController: line 199, column 18: Variable does not exist: Name
ZuoraNewContractController: line 201, column 18: Variable does not exist: Website
ZuoraNewContractController: line 202, column 18: Variable does not exist: Phone
ZuoraNewContractController: line 203, column 18: Variable does not exist: BillingStreet
ZuoraNewContractController: line 204, column 18: Variable does not exist: BillingCity
ZuoraNewContractController: line 205, column 18: Variable does not exist: BillingState
ZuoraNewContractController: line 206, column 18: Variable does not exist: BillingPostalCode
ZuoraNewContractController: line 207, column 18: Variable does not exist: BillingCountryCode
ZuoraNewContractController: line 217, column 9: DML requires SObject or SObject list type: Account
ZuoraNewContractController: line 360, column 26: Variable does not exist: Id
ZuoraNewContractController: line 362, column 26: Variable does not exist: Name
ZuoraNewContractController_Test: line 6, column 15: Invalid constructor syntax, name=value pairs can only be used for SObjects: Account
ZuoraNewContractController_Test: line 7, column 3: DML requires SObject or SObject list type: Account
ZuoraNewContractController_Test: line 8, column 74: Variable does not exist: id
ZuoraNewContractController_Test: line 10, column 77: Variable does not exist: id
ZuoraNewContractController_Test: line 12, column 48: Variable does not exist: id
ZuoraNewContractController_Test: line 22, column 25: Variable does not exist: id
ZuoraPaymentUpdateController: line 80, column 22: Illegal assignment from List<Account> to List<Account>
ZuoraPaymentUpdateController: line 86, column 37: Variable does not exist: Name
ZuoraPaymentUpdateControllerTest: line 18, column 18: Invalid constructor syntax, name=value pairs can only be used for SObjects: Account
ZuoraPaymentUpdateControllerTest: line 19, column 3: DML requires SObject or SObject list type: Account
ZuoraPaymentUpdateControllerTest: line 25, column 91: Variable does not exist: id
ZuoraPaymentUpdateControllerTest: line 84, column 18: Invalid constructor syntax, name=value pairs can only be used for SObjects: Account
ZuoraPaymentUpdateControllerTest: line 85, column 3: DML requires SObject or SObject list type: Account
ZuoraPaymentUpdateControllerTest: line 91, column 91: Variable does not exist: id

 
PawanKumarPawanKumar
Hi Kurt,
You will get this when you are expectng n result from SOQL, but it is giving more than one record.

e.g. 
Account queriedAccount = [Select Id from Account Limit 1];

The above will work fine always as you are limiting return record to 1.

But If you remove limit 1 from SOQL as shown in below SOQL query, then you query will return List<Account> instead single Account record;  this time you will get the same error what you are getting currently.
Account queriedAccount = [Select Id from Account]; // to avoid such error we should use list always as below.

// best practise
List<Account> queriedAccount = [Select Id from Account];// this will never throw such error.

Please let me know if it helps you.

Regards,
Pawan Kumar
This was selected as the best answer
Kurt AlmeidaKurt Almeida
Thank You! We were developing some things and named a class "Acount" which in turn confused Salesforce. Not the best naming convention and a great way to confuse the system.