Reputation: 39
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?
Upvotes: 0
Views: 6162
Reputation: 19050
you have declared contactInsertItem to be a list of contacts, but the code with error is trying to treat it as a single contact. You want contactInsertItem
to be a Contact
, not List<Contact>
Upvotes: 2