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

error:unexpected token: 'Account'

i am trying to create contact upon account insertion
public static Account createContact()
   {   List<account> acc= new List<Account>();
       for(Account a :
       Contact c=new Contact();
        insert acc;     
but there is error    
unexpected token: 'Account'
Best Answer chosen by Force.platform
sravan velamasravan velama
Hi Arati,

You are adding the Contact object instance to Account List, which is Wrong.
For you scenario, the code would be:

Trigger ContactInsertor on Account (after insert) {
List<Contact> conList = new List<Contact>();
if(Trigger.isAfter && Trigger.isInsert){
for(Account a : {
Conatct c = new Contact();
 insert conList;