I have a field on Task Test_Time__c
(Date/Time). How can I fetch this field and populate on Last_Login_Time__c
on Related Contact record?
Below is task on Contact
Below is the related Contact
Tried to add this trigger on Task
trigger lastLogin on Task (after insert, after update, before insert, before update) {
Map<Id, List<Task>> taskWhatIds = new Map<Id, List<Task>>{};
for (Task t : trigger.new) {
if (t.WhatId != null) {
List<Task> tasks = taskWhatIds.get(t.WhatId);
if (tasks == null) {
tasks = new List<Task>();
taskWhatIds.put(t.WhatId, tasks);
}
tasks.add(t);
}
}
for (Contact c: [Select Id, Last_login_time__c FROM Contact WHERE Id IN :taskWhatIds.keySet()]){
for (task t : taskWhatIds.get(c.id)){
t.test_time__c = c.last_login_time__c;
}
}
}