You need to sign in to do that
Don't have an account?

Initial term of field expression must be a concrete SObject: List
Hello,
Im receiving the error in the subject line. Im trying to loop through records in a custom object and load them into the Contact object. Here is the code...
public list<Contact> contactInsertItem {get;set;} public list<Contact> contactInsertList {get;set;} public SalesConnectContactQuickBuildController (ApexPages.StandardSetController controller) { ... List<CustomObject1__c> unmatchedContactList = new List<CustomObject1__c>([SELECT field1__c, field2__c, field3__c FROM CustomObject1__c WHERE Id in :tempSet]); for(integer i=0; i<unmatchedContactList.size();i++){ contactInsertItem = new list<Contact>(); //***error occurs here*** contactInsertItem.field1__c = unmatchedContactList[i].field1__c; contactInsertItem.field2__c = unmatchedContactList[i].field2__c; contactInsertItem.field3__c = unmatchedContactList[i].field3__c; contactInsertItem.field4__c = unmatchedContactList[i].field4__c; contactInsertItem.field5__c = unmatchedContactList[i].field5__c; contactInsertList.add(contactInsertItem); } ... }
What am I doing incorrectly?
You are trying to reference properties on a list collection instead of on the object.
Try changing these items:
public list<Contact> contactInsertItem {get;set;}
contactInsertItem = new list<Contact>();
to this:
public Contact contactInsertItem {get;set;}
contactInsertItem = new Contact();
Alternatively, in your loop use:
Contact con = new Contact();
con.field1__c = unmatchedContactList[i].field1__c;
con.field2__c = unmatchedContactList[i].field2__c;
con.field3__c = unmatchedContactList[i].field3__c;
con.field4__c = unmatchedContactList[i].field4__c;
con.field5__c = unmatchedContactList[i].field5__c;
contactInsertList.add(con);
All Answers
You are trying to reference properties on a list collection instead of on the object.
Try changing these items:
public list<Contact> contactInsertItem {get;set;}
contactInsertItem = new list<Contact>();
to this:
public Contact contactInsertItem {get;set;}
contactInsertItem = new Contact();
Alternatively, in your loop use:
Contact con = new Contact();
con.field1__c = unmatchedContactList[i].field1__c;
con.field2__c = unmatchedContactList[i].field2__c;
con.field3__c = unmatchedContactList[i].field3__c;
con.field4__c = unmatchedContactList[i].field4__c;
con.field5__c = unmatchedContactList[i].field5__c;
contactInsertList.add(con);