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
vijay kumar 300vijay kumar 300 

Trigger on Account

Hi All,


When ever new Account record is successfully created  the create the corresponding  contact record for the account with
account name as contact lastname
account phone as contact phone
Best Answer chosen by vijay kumar 300
Thota Rakesh 1Thota Rakesh 1
Hi Vijay kumar 300,

For your above requirement use below code, its working fine in my org.

Trigger Code:
 
trigger accountAfter on Account (after insert) {
    List<Contact> cons=new List<Contact>();
    for(Account a: Trigger.New){
        Contact c=new Contact();
        c.accountid=a.id;
        c.lastname=a.name;
        c.phone=a.phone;
        cons.add(c);
    }
    insert cons;

}


Kindly mark it as solved if it helps you.


Best Regards,
Rakesh.T



 

All Answers

Thota Rakesh 1Thota Rakesh 1
Hi Vijay kumar 300,

For your above requirement use below code, its working fine in my org.

Trigger Code:
 
trigger accountAfter on Account (after insert) {
    List<Contact> cons=new List<Contact>();
    for(Account a: Trigger.New){
        Contact c=new Contact();
        c.accountid=a.id;
        c.lastname=a.name;
        c.phone=a.phone;
        cons.add(c);
    }
    insert cons;

}


Kindly mark it as solved if it helps you.


Best Regards,
Rakesh.T



 
This was selected as the best answer
akkkakkk
Trigger TriggerName on Account(after insert){
   Contact cont=new Contact();
cont.lastName=trigger.new[0].name;
cont.accountId=trigger.new[0].ID
insert cont;
}