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
Amit Kr SinghAmit Kr Singh 

Trigger for update child object field value with parent object value

Hi All,

In my current senario i am having Account object and Contact object

In Account object  field name is   Atest__c
and Contact Object field anme IS Ctest__c

i want to update Contact  object Ctest__c  field  value with Account Atest__c value 

so plz help me to write trigger
thanks
Arunkumar RArunkumar R
trigger ContactTrigger on Contact(after insert, after update)
{
   List<Account> accList = new List<Account>();
    for(contact cnt : Trigger.new)
   {
       if(cnt.accountid != null)
      {
         Account acc = new Account();
         acc.Id = cnt.accountid;
         acc.Atest__c = cnt.Ctest__c ;
         accList.add(acc);

       }
   }

​   update accList;
}

The above is basic to update parent field value, you can add/change such as comparing old value with new or anything according to your need.