I'm trying to work with contacts in a salesforce org, where Person Accounts are enabled. Apparently, you can not query contacts anymore. A simple query like:

List<Contact> cs = [SELECT Id, LastName FROM Contact];

fails, because of:

Line: 1, Column: 15
Illegal assignment from List<Contact> to List<Contact>


List<Contact> cs = [SELECT Id, LastName FROM Contact WHERE IsPersonAccount = false];

also fails (same error). The query works as expected with the Query Editor, though. To make things even worse, when loading the records in List<sObject> sobjs, I can not cast them later into contacts.

for (sObject obj : sObjs)

returns "Contact", but

Contact c = (Contact) obj;

just throws Incompatible types since an instance of SObject is never an instance of Contact. Needless to say, that I can not access any fields, and the code works perfectly when querying other sObjects such as leads.

Please help me :(


1 Answer 1


You definitely can execute

List<Contact> cs = [SELECT Id, LastName FROM Contact];

In an org with person accounts.

Often the explanation for weird compiler errors like this is having created an Apex Class of your own called Contact. Then the list on the left-hand-side ends up referring to your class, and the right-hand-side is the sObject. It also happens pretty often if someone creates a class called Test.

  • 1
    Thank you so much. I figured that out by myself literally seconds before I read your response :). Commented Feb 22, 2018 at 10:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .