Question:
I need to create a trigger that does the following:
Whenever a new task with a subject of "Email: CO1 Feedback" is created on a contact record, a field on that contact record called "CO1_followup_email_date__c" should be updated to match the date that the task was created.
The code that I used is below. I am not getting any error messages, but when I create the task with the proper subject line, the CO1 Follow-up email date is not updated. Any ideas?? Thanks for your help!
Solution:
Its whoId not WhatId... update to..
Contact c = new Contact(Id=t.WhoId);
I need to create a trigger that does the following:
Whenever a new task with a subject of "Email: CO1 Feedback" is created on a contact record, a field on that contact record called "CO1_followup_email_date__c" should be updated to match the date that the task was created.
The code that I used is below. I am not getting any error messages, but when I create the task with the proper subject line, the CO1 Follow-up email date is not updated. Any ideas?? Thanks for your help!
trigger Contactbirthdayupdate on Task (after insert) { List<Contact> ContactsToUpdate = new List<Contact>(); for (Task t: Trigger.new) { if (t.subject=='Email: CO1 Feedback') { Contact c = new Contact(Id=t.WhatId); c.CO1_Followup_email_date__c = t.ActivityDate; ContactsToUpdate.add(c); } } try { update ContactsToUpdate; } catch (system.Dmlexception e) { system.debug (e); } }
Solution:
Its whoId not WhatId... update to..
Contact c = new Contact(Id=t.WhoId);
No comments:
Post a Comment