字段表达式的初始术语必须是具体的SObject:List

时间:2013-11-25 22:43:23

标签: salesforce apex-code

我在主题行中收到错误。我试图循环自定义对象中的记录并将它们加载到Contact对象中。这是代码......

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);
    }
...
}

我做错了什么?

1 个答案:

答案 0 :(得分:2)

您已将contactInsertItem声明为联系人列表,但有错误的代码正在尝试将其视为单个联系人。您希望contactInsertItem成为Contact,而不是List<Contact>