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
Abhi CharlesAbhi Charles 

Hi need help

Hi this is my code what i am doing is that i am updating a custum field with activitydate of task. But when my trigger fires the custom field is showing wrong value e.g.

 

ActivityDate ::: 24/7/2012

Custom Field ::: 23/7/2012

This custom field is also datetime field.

 

Here is my code::::::::::::::::::::::::::::::::::::::>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<:::::::::::::::::::::::::::::::::::::::::::::::::

 

trigger UpdateTaskActivityTypeEmail on Task (before insert, before update) {
    String subject;
    for (Task tsk : trigger.new)
      {     
          if(trigger.isInsert || (trigger.isUpdate && tsk.ActivityDate != trigger.oldMap.get(tsk.Id).ActivityDate))
          {
             tsk.Activity_Date__c = tsk.ActivityDate;
          }   
         subject = tsk.Subject;
         if (subject != null && subject.trim() != '' && subject.toLowerCase().contains('email:'))
         {                  
            tsk.aos__Activity_Type__c ='Email (customer or prospect)';
         }
      }
}

 

Any help is highly appreciated...

AmitSahuAmitSahu
For this requirement do you really need the code or a Formjula field can do the trick for you ?
Saikishore Reddy AengareddySaikishore Reddy Aengareddy

Abhi,

 

First thing, ActivityDate is NOT a Datetime field... Here you are trying to update datetime custom field from a Date field... If you still want this to happen you can use...

 

tsk.Activity_Date__c = datetime.newInstance(tsk.ActivityDate.year(),tsk.ActivityDate.month(),tsk.ActivityDate.day());

 

instead of  tsk.Activity_Date__c = tsk.ActivityDate;

 

Hope this helps!