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
Disha ThakurDisha Thakur 

Hi, I am trying to update birthdate of most recent contact on Account. It should work on insert and update. It is not showing error but it is not working. What should I do?

trigger BirthdateTrigger on Account (after insert, after update) {
List<Account> acc= new List<Account>();
    if(trigger.isInsert || trigger.isUpdate)
{
    acc = [select Id,(select Birthdate from Contacts ORDER BY CreatedDate DESC LIMIT 1) from Account where Id IN :trigger.new];
     for(Account a : acc)
     {
         for(Contact c : a.Contacts)
         c.Birthdate = Date.newInstance(2000,06,12);
         System.debug('Birthdate updated');
     }
}
}
Naveen KNNaveen KN
add all your contacts to the new list and update the contact list. 

--
Naveen K N