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 

By updating parent record then child record shoud automatically updated? with example account,contact

Jayant JadhavJayant Jadhav
@Sai,

You can do this by using two ways based on your requirement.
  1. By usgin cross object formula field on Contact object. (contact field will be read only bcz of formula field)
  2. By using trigger. Write trigger on Account object and update the child records.
Let me know if you need more information on any of this option.
Amit Chaudhary 8Amit Chaudhary 8
Hi Sai,

Option 1:- Please create cross object formula field on Contact object
Option 2:- Your can create trigger on Account object to update all child Contact
Sample Trigger for you
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 let us know if this will help you
David Holland 6David Holland 6
Why not use the process builder?

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

https://developer.salesforce.com/trailhead/business_process_automation/process_builder