Friday, 10 August 2012

Trigger to update a field in parent record once a task is created

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:
if (t.subject=='Email: CO1 Feedback')
Contact c = new Contact(Id=t.WhatId);

c.CO1_Followup_email_date__c = t.ActivityDate;
   try {
        update ContactsToUpdate; 
    } catch (system.Dmlexception e) {
        system.debug (e);


Its whoId not WhatId... update to..

Contact c = new Contact(Id=t.WhoId);

No comments:

Post a Comment