+ Start a Discussion
Force.platformForce.platform 

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 : Trigger.new)
       {
       Contact c=new Contact();
       C.LastName='Sharma';
       c.Description=a.name;
       acc.add(c);
       } 
        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 : trigger.new) {
Conatct c = new Contact();
 c.LastName='Sharma';
 c.Description=a.name;
 conList.add(c);
}
 insert conList;
}
}











}