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
Suresh Kumar 34Suresh Kumar 34 

trigger for creating a contact

hi all,

please help me in creating a trigger for creating a contact when account is created.

Thank you,
Suresh kumar
PRIYATAM REDDYPRIYATAM REDDY
trigger createContact on Account(after insert){

Account acc = trigger.new[0];
Contact c = new Contact();
c.Lastname=acc.Name;
c.AccountId=acc.Id;
insert c;

}
Amit Chaudhary 8Amit Chaudhary 8
trigger AccountTrigger on Account( after insert)
{
	List<Contact> lstCont = new List<Contact>();
	For(Acount acc: trigger.New)
	{
		Contact cont = new Contact();
		cont.firstName='Test';
		cont.LastName ='Trigger';
		cont.accountId = acc.id;
		lstCont.add(cont);
	}
	if(lstCont.size() > 0 )
	{
		insert lstCont;
	}
}
Plese try above code