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
AzusfdcAzusfdc 

I have written both triggers needed to be one would any body make it as one ?

trigger trgset on contact (after insert)
{
    List<Contact> conToUpdate = new List<Contact>() ;
     for(Account acc : [Select Name,(Select id ,LastName from Contacts where id in: trigger.new ) from Account  ] )
     {
         for(Contact con : acc.Contacts)
         {
             con.LastName = acc.Name ;
             conToUpdate.add(con) ;
         }
    }
    if(conTOUpdate.size() > 0)
    {
       update conTOUpdate ;
    }
}
 
Trigger Childtoconupdate on ChildtoContact__c(after insert)
{
	List<ChildtoContact__c> ctlist=new List<ChildtoContact__c>();
	for(contact con:[Select lastname,(select id,name from ChildtoContactsrelation__r where id in:trigger.new)
		from Contact])
	{
		for(ChildtoContact__c ct:con.ChildtoContactsrelation__r)
		{
			ct.name=con.LastName;
			ctlist.add(ct);
		}
	}
	if(ctlist.size()>0)
	{
		Update ctlist;
	}
}

 
doravmondoravmon
These two trigger on different object, can't combine...
AzusfdcAzusfdc
here is the relationship contact is parent of ChildtoContact__c