You need to sign in to do that
Don't have an account?

insert based trigger
trigger InsertBefore on Account (after insert)
{
List<Contact>contdetail = new List<Contact>();
Map<Id, Account>mapaccount = new Map<Id, Account>([Select Id, name, phone,
(Select Id,FirstName, LastName, phone From Contacts
)From Account Where Id In : Trigger.New]);
for(Account a : Trigger.New)
{
if(mapaccount.get(a.Id).contacts.size() == 0)
{
contdetail.add(new Contact(FirstName =a.Name, LastName =a.Name, Phone =a.phone, AccountId =a.Id));
}
}
}
{
List<Contact>contdetail = new List<Contact>();
Map<Id, Account>mapaccount = new Map<Id, Account>([Select Id, name, phone,
(Select Id,FirstName, LastName, phone From Contacts
)From Account Where Id In : Trigger.New]);
for(Account a : Trigger.New)
{
if(mapaccount.get(a.Id).contacts.size() == 0)
{
contdetail.add(new Contact(FirstName =a.Name, LastName =a.Name, Phone =a.phone, AccountId =a.Id));
}
}
}
It may help others.
All Answers
It may help others.