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
John StamersJohn Stamers 

Update Task datetime field from a custom field

Hello all,

I'm working on a trigger that assigns a time specific task to an object I call subject. Here is what I have so far:

trigger CreateBloodDrawTasks on Blood_Draw__c (after insert) {
    for(Blood_Draw__c c1:trigger.new){
        List<Subject__c> c2=[select id,Trial__c from Subject__c where Trial__c=:c1.Trial__c];
        list<task> tasklist=new list<task>();
        for(Subject__c c2a:c2){
            Task tsk=new Task();
            tsk.WhatId=c2a.id;
            tsk.Subject='Blood Draw - ' + c1.Name + ' hrs';
            tsk.activitydate = c1.Dosing_Start__c;
            tasklist.add(tsk);
        }
        insert tasklist;      
    }
}

This generates the following Error: Compile Error: Invalid field Dosing_Start__c for SObject Blood_Draw__c at line 9 column 32

I'm not sure what's causing this as both fields are already in the date/time format. Does anyone have any ideas?

Thanks!
John
Marty C.Marty C.

Hello, John, two possibilities come to mind for why you're seeing the error.

  • Are you sure you're writing the field name correctly? This seems elementary, but I'm sure even experienced developers run into this gotcha every once in a while.
  • Is the Dosing_Start__c field's field permissions (a.k.a. field-level security) configured to make it at least Visible to your profile (I'm guessing System Administrator)? It's possible that even the System Administrator profile does not have the Visible field permission assigned, in which case you will also get that error when trying to compile code.
Boom B OpFocusBoom B OpFocus
Hi John,

I think the Task.ActivityDate is actually a Date field.  Did you try to convert the Dosing_Start__c to a Date field (like this Date.valueOf(c1.Dosing_Start__c))?
John StamersJohn Stamers
updated the code to the line now looks like:

tsk.activitydate = Date.valueOf(c1.Dosing_Start__c);

Unfortunatley it's still churning out the same error: Compile Error: Invalid field Dosing_Start__c for SObject Blood_Draw__c at line 9 column 45