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
AhensAhens 

Compiler error, SOQL query to List<Contact>

Hello, 

 

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! 

r1985r1985

Hi,

 

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

 

 

 

 

Thanks,

MVP

vishal@forcevishal@force

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!

 

 

aebenaeben

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. :)

vishal@forcevishal@force

^ 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

 

AhensAhens

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. :)