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
Jakson MonteiroJakson Monteiro 

Link Account to a Contact using trigger?

trigger AddAccount on Contact (before insert) 
{
 for (Contact c:Trigger.new )
 {
    Account a= new Account();
    a.Name='ACME';
    a.ID=c.AccountID;
    
    insert a;
 
 }

}


how can i link a Account to a contact ??
Vivek_PatelVivek_Patel
Hi Jakson,

Just add c.AccountId = a.Id after insert a;

Regards,
Vivek Patel.
Vivek_PatelVivek_Patel
Also remove the line a.Id = c.AccountId
Vishal NegandhiVishal Negandhi
Please go through the same trigger below:


trigger AddAccount on Contact (before insert) 
{
 for (Contact c:Trigger.new )
 {
    c.AccountId = the account id you want to relate it to // this would ideally be coming from some logic otherwise you need not write this trigger
 }

}