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
Abhishek Rajput 20Abhishek Rajput 20 

populate the name of child accouunts on parent account

I need a trigger to populate the name of child accounts on parent account.

Please help me on this.
bob_buzzardbob_buzzard
If you want help, that implies you have had a go yourself. Is that the case? Or are you asking for someone to write the trigger from scratch for you?
Amit Chaudhary 8Amit Chaudhary 8
Please try below code I hope that will help you
trigger AccountTrigger on Account( after insert, after update)
{
	Set<ID> setParentAccId = new Set<ID>();
	for(Account acc : Trigger.New)
	{
		if(acc.ParentId != null)
		{
			setParentAccId.add(acc.ParentId);
		}
	}
	
	if(setParentAccId.size() > 0 )
	{
		Map<ID,Account> mapParentAccount = new Map<ID,Account>([select id,ChildAccountName__C from account where id in :setParentAccId ]);
		List<Account> lstParentAcc = new List<Account>();
		for(Account acc : Trigger.New)
		{
			if(acc.ParentId != null && mapParentAccount.containsKey(acc.ParentId) )
			{
				Account parentAcc = mapParentAccount.get(acc.ParentId);
				parentAcc.ChildAccountName__C = acc.Name;
				lstParentAcc.add(parentAcc);
			}
		}
		if(lstParentAcc.size() > 0 )
		{
			update lstParentAcc;
		}
	}
}
NOTE:- please change Field API name according to your org.

Please check below post. I hope that will help you
http://amitsalesforce.blogspot.in/search/label/Trigger

Please let us know if this will help you

Thanks
AMit Chaudhary