我有一个代码检查用户的查询数据库,如果用户不存在,那么代码将在联系人中创建一个新用户,
这里只是部分代码:
newcontact = [SELECT Id, FirstName FROM Contact WHERE Contact.Email =inquery.email__c];
if(newcontact.size() == 0) {
Account[] aa = [SELECT Id FROM Account WHERE Name = :inquery.Institution__c];
contact = new Contact();
contact.FirstName = inquery.First_Name__c;
contact.LastName = inquery.Last_Name__c;
contact.Email = inquery.email__c;
contact.AccountId = aa.Id;
try {
insert contact; // inserts the new record into the database
} catch (DMLException e) {
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error creating new contact'));
return null;
}
我正在尝试将该用户与现有帐户相关联?
但是以下行给了我一个错误:
contact.AccountId = aa.Id;
哪个是
Initial term of field expression must be a concrete SObject: LIST<Account> at line
并且 aa.size() 返回 1,因为它应该存在,因为帐户存在,
有人可以告诉我有什么问题吗?
谢谢