+ 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');
     }
}
}
Team  CodEngine.inTeam CodEngine.in
add all your contacts to the new list and update the contact list. 

--
Naveen K N