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
beginnervbeginnerv 

trigger to create an contact wherever the account is created for specific set of users(say i have a set of 5 users and whenever they try to create or update an account the contact should be created or updated accordingly)

Best Answer chosen by beginnerv
Agustina GarciaAgustina Garcia
Which fields do you want to modify?

This is a scheleton of the trigger. Add the fields you need to copy from Account into Contact, and let us know if you still have issues
 
trigger CreateContact on Account (After Insert, After Update)
{
	List<Contact> freshContacts = new List<Contact>();
	if(Trigger.isInsert || Trigger.isUpdate)
    {
        for(Account acc : trigger.new)
        {
            // For each Account create a new Contact.
     		Contact freshCon=new Contact();
            //add the information
            freshContacts.add(freshCon);
        }
        upsert freshContacts;
        
        //If you need to check during the update old values you can also do
        /*if(Trigger.isUpdate)
        {
        	for(Account acc : trigger.new)
        	{
            	Account oldAcc = trigger.oldMap.get(acc.Id);
                //check oldAcc values with acc one                
        	}
        }*/
    }
}