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
Greg Palmer 13Greg Palmer 13 

Creating contacts for accounts where there is no linked contact

I am looking for the best way of looping through all of the accounts in our salesforce instance.

Where no contact is associated with that account, I would like to create a contact, pulling specific information from the account to populate the fields of the contact.

Could someone point me in the right direction.
Balaji BondarBalaji Bondar
Hi Greg,

You have to write after insert trigger on contact.Check if account is associated with the Account and populate the fields of the contact based on your reqruirement.
trigger PopulateContactinfo on Contact (before insert){
	for(Contact contactObj : Trigger.New){
		if(contactObj.AccountId == Null){
			//your custom logic to populate contact info
		}
	}
}

Important :
If this is what you were looking for then please mark it as a "SOLUTION" or You can Click on the "Like" Button if this was beneficial for you.