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
TehNrdTehNrd 

Compile Error: Illegal assignment from LIST:SOBJECT:Contact to LIST:contact

Illegal assignment from a Contact List to a contact list.....hmmmmm. Seems the compiler is having issues with case sensitivity.

This only happens in Summer08. Here is the code to reproduce:

Code:
List<Contact> cons = new List<Contact>();
cons = [select Id, Name from Contact limit 10]; 

 

SuperfellSuperfell
Are you sure you don't have an in scope apex class called contact ?
TehNrdTehNrd
Doh! That was totally it. This is actually in a controller for a Visualforce page and not thinking I named the controller "contact". Perhaps there should be a warning when you name a class the same as a standard or custom sObject?


Message Edited by TehNrd on 06-04-2008 11:09 AM
TehNrdTehNrd
Well,maybe that wasn't it: Here is the class I am trying to save:

Code:
public class contactTest {
String contactId;
List<SelectOption> contacts;
Map<Id,Contact> contactMap = new Map<Id,Contact>();
Contact c;

public String getContactId(){
 return contactID;
}

public void setContactID(String contactId){
 this.contactId = contactId;
}

public List<SelectOption> getContacts(){
if(contacts == null){
 Contact [] cons = [select Id, Name, Title, FirstName, LastName, Phone, Email from Contact limit 10];
 contactId = cons[0].Id;
 contacts = new List<SelectOption>();

 for(Contact c : cons){
  contacts.add(new SelectOption(c.ID,c.Name));
  contactMap.put(c.Id,c);
 }
}
return contacts;
}

public Contact getContactInfo(){
 c = contactMap.get(getContactID());
 return c;
}

}

 

TehNrdTehNrd
I thought maybe the name contactTest was causing issues so I tried again. With the code below I copied from Spring 08 to Summer 08. In spring it is fine but in summer I get the error:

Code:
public class input {
String contactId;
List<SelectOption> contacts;
Map<Id,Contact> contactMap = new Map<Id,Contact>();
Contact c;

public String getContactId(){
return contactID;
}

public void setContactID(String contactId){
this.contactId = contactId;

}

public List<SelectOption> getContacts(){
if(contacts == null){
Contact [] cons = [select Id, Name, Title, FirstName, LastName, Phone, Email from Contact limit 10];
contactId = cons[0].Id;
contacts = new List<SelectOption>();

for(Contact c : cons){
contacts.add(new SelectOption(c.ID,c.Name));
contactMap.put(c.Id,c);
}
}
return contacts;
}

public Contact getContactInfo(){
c = contactMap.get(getContactID());
return c;
}
}

 





Message Edited by TehNrd on 06-04-2008 11:21 AM
TehNrdTehNrd
Fixed! Phew ;)

It was the original issue SimonF mentioned. I never deleted the original contact class I created.

A word to the wise. Don't accidentally create classes with the same name as sObjects.


Message Edited by TehNrd on 06-04-2008 11:49 AM
harry63harry63

NOT ABLE TO SORT BASED ON COLOUMNS.GETTING ERROR AT DATABASE.QUERY()

//Our collection of the class/wrapper objects cContact public List contactList {get; set;} //This method uses a simple SOQL query to return a List of Contacts public List getContacts(){ if(contactList == null){ contactList = new List(); for(Contact c : [Select Title,Account.RecordType.Name,Account.Name, AccountId,Name,Id,Email,Phone,mailingstreet,mailingcity,mailingstate,mailingcountry from Contact]) { contactList.add(new cContact(c)); } } return contactList; } public string sortfield1{get;set;} public void doconssort() { List ct2; List sortcons=new List(); if(contactlist.size()>0) { for(integer i=contactlist.size();i>0;i--) { sortcons.add(contactlist[i-1]); } contactlist.clear(); contactlist.addAll(sortcons); ct2=database.query(contactlist + ‘ order by ‘ + ‘ + sortfield1 + ‘ ‘ + ‘ limit 20’); } } VF page

AneskeAneske

had the same error and found that I also had a different class with the same name as the object ..Contact.. Tx guys

G_G_

Thanks this helped I did this as well!

PNandPNand

Thanks for the post ..Yes it is true,I am getting similar error for Opportunity also but what is the reason behind this?

TehNrdTehNrd

You probably have an Apex class named Opportunity. Apex classes should not have the same name as standard or custom objects.

Prasanth NannapaneniPrasanth Nannapaneni
I'm getting these errors. I need help. Please check and respond if someone could understand and let me know the solution.