function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Prince_sfdcPrince_sfdc 

Error while writing a trigger on Account

Initial term of field expression 
​must be a concrete SObject: List<Contact> at line 12 column 6.
 
trigger CreateContact on Account (After Insert)
{
 
 //Collection of contacts for saving new contacts.
 List<Contact> conList =new List<Contact>();
 
 for(Account acc: trigger.new)
 {
     // For each Account create a new Contact.
     List<Contact> freshCon=new List<Contact>();
     
     freshcon.Accountid=acc.id;
     freshcon.LastName=acc.Name +'_'+ acc.CustomerPriority__c;
     
     //add new Contact to the collection.
     conList.add(freshcon);
     
 }
 
insert conList;
 

}
Best Answer chosen by Prince_sfdc
Agustina GarciaAgustina Garcia
Hi,

I think this is a copy-paste issue. Look at line 10. You are creating a list of Contacts call freshCon and then used it like it was a single item.

Just replace the list for a single record. Like this:
 
trigger CreateContact on Account (After Insert)
{
 
 //Collection of contacts for saving new contacts.
 List<Contact> conList =new List<Contact>();
 
 for(Account acc: trigger.new)
 {
     // For each Account create a new Contact.
     Contact freshCon=new Contact();
     
     freshcon.Accountid=acc.id;
     freshcon.LastName=acc.Name +'_'+ acc.CustomerPriority__c;
     
     //add new Contact to the collection.
     conList.add(freshcon);
     
 }
 
insert conList;
 

}

Hope this help.