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
sai kumar 49sai kumar 49 

create trigger on Account object to update all child Contact..........

ManojjenaManojjena
Hi Sai ,

What you want to update in contacts ?
When you want to update ,on updat eof Account if yes which field value you want to update in contact ,any fields from Account or any independent contact field you need to update ?
 
David Holland 6David Holland 6

Why not use the process builder?

You can update all child records based on parent record update.

Please see below:


https://developer.salesforce.com/trailhead/business_process_automation/process_builder
Amit Chaudhary 8Amit Chaudhary 8
Please try below code:-
trigger AccountTrigger on Account ( after insert, after update ) 
{

	Set<String> setAccountID = new Set<String>();
	For(Account acc: trigger.New)
	{
		setAccountID.add(acc.id);
	}
	
	List<Account> listAccount =[select id,name, (Select, firstName, LastName fromm Contacts) from account where id in :setAccountID ];
	
	For( Account acc: listAccount )
	{
		System.debug('----------->'+acc.Name);
		List<Contact> lstContact = acc.Contacts;
		for(Contact cont : lstContact)
		{
			System.debug('----------->'+cont.firstName);
			// Add all your logic here
		}
	}
	
}

Please mark this as solution if this will help you.