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 

Task Trigger updating parent record

I'm trying to get the first completed task logged on a case to fill in the current date/time into a field on the case called"First_touch_case__c". I don't want it to update the date/time if another task is logged. Basically if First_touch_case__c is not null, it shouldn't update it with system.now

 

Here is my code. I'm sure I'm missing something easy, but basically it keeps updating the "First_touch_case__c" field everytime a task is logged.

 

trigger CaseFirstTouch on Task (after insert) { List<Case> CasesToUpdate = new List<Case>(); for (Task t: Trigger.new) { if (t.Status=='Completed') { Case c = new Case(Id=t.WhatId); if (c.First_Touch_Case__c == null) { c.First_Touch_Case__c = System.now(); CasesToUpdate.add(c); } } } update CasesToUpdate; }

 

 

Thanks,

 

Chris

 

hisrinuhisrinu

As you have not queried from the data base, the value in the field 'c.First_Touch_Case__c' will be null.

i.e the reason the field is getting populated each and every time.

BobBob

How can I accomplish something similar to this with events? I want to drive the start time from the event to a custom field on a case page. All I need is the event start date & time to populate a field on the case it is related to with the date and time. 

 

Lets says the custom field is call Event Start Date__c.