+ Start a Discussion

Compiler error, SOQL query to List<Contact>



Here is the error I receive, 

Error: ContactController Compile Error: Illegal assignment from LIST<Contact> to LIST<Contact> at line 11 column 9


Below is the simplified version of my Apex class: 


public class ContactController {       

public void getContact() {       

List<Contact> d = [select id, name from Contact where id = :ApexPages.currentPage().getParameters().get('id')];           }      



I tried casting the query result to (List<Contact>), which gives me the following error:

Error: ContactController Compile Error: Incompatible types since an instance of LIST<Contact> is never an instance of LIST<Contact> at line 4 column 27


Thanks for the help! 




Change the name of the class as it is stored keyword. Then it will work fine.








It has nothing to do with the class name, I was able to store the same code with the mentioned class name in my dev org.


I faced a similar issue when I was assigning values from a query to a list of Account.


After wasting a lot of time, I found out that it was a salesforce bug. I deleted the class, saved it again and it got saved without any changes.


Give it a try!




Another APEX weiredness!! I have had issues like this before. Guess what? it went away on its own. Go have a drink. When you return, it will start working. :)


^ I second him :D

Rahul SharmaRahul Sharma

hi Ahens,

try to put ID in string then use in query:


public class ContactController {       
public void getContact() { 
String strContactId = ApexPages.currentPage().getParameters().get('id');
List<Contact> lstContact = [select id, name from Contact where id = :strContactId];
} }

 Really weird :P



Thanks for all the replies! :)


I opened a case with Support to see if there was any work-around this bug. 

It turned out that I had some random empy class called 'Contact' which was the problem. I deleted it off and it works fine now. :)