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
LuvaraLuvara 

Updating Parent Object from a Task

Hi all, I'm trying to update an Account's date field (Last Referenced) whenever a task is saved with a certain record type (012000000008llU).

The systems says it's valid, but doesn't seem to be working. Can anyone provide some guidance?


Code:
trigger UpdateAccountLastRef on Task (after update)
{
for (Task t:System.Trigger.new)

{if (t.RecordTypeId=='012000000008llU') {
   Account acc = new Account(Id=t.AccountId, Last_Referenced__c=System.today());update acc;
     }
   
}}

Thanks,

Chris
 

werewolfwerewolf
That generally looks OK.  Maybe put a couple of System.debug() statements and run it through the debug log to see where it's crapping out?  One thing you'll want to check is whether t.AccountId is consistently filled.
LuvaraLuvara
I figured it out, It's always something simple..  I copied the recordtype ID from my production org which was actually different than my dev org.. doh :smileyhappy:

Thanks,

Chris