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
wedaftwedaft 

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: 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);
    }
}

 

Best Answer chosen by Admin (Salesforce Developers) 
Saikishore Reddy AengareddySaikishore Reddy Aengareddy

Its whoId not WhatId... update to..

 

 

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

All Answers

Saikishore Reddy AengareddySaikishore Reddy Aengareddy

Its whoId not WhatId... update to..

 

 

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

This was selected as the best answer
wedaftwedaft

Ah, yes that makes sense. Thanks!