+ Start a Discussion
David Gunn 17David Gunn 17 

Apex: How to access task.CreatedDate?

I have a new class that I'm trying to save but I'm getting this error: Error:

Compile Error: Variable does not exist: CreatedDate at line 25 column 27

This is where it's getting tripped up:
DateTime myDate = taskList[0].CreatedDate;
taskList is a list of (passed in from a trigger) tasks.  CreatedDate is a standard task field.  Why is it getting a "variable does not exist" error?
 
Best Answer chosen by David Gunn 17
David Gunn 17David Gunn 17
The problem was that I had named my class Task.  Renamed it to TaskUtility and the error no longer happens.

All Answers

Raj VakatiRaj Vakati
Hi David , 
It's should work. Can you share the code see the error? i believe this was not an error 
DateTime dt = t.CreatedDate ;


 
David Gunn 17David Gunn 17
Raj,

I think it should work too but it doesn't.

I tried this and got the same error:
 
Task myTask = new Task();
DateTime myDate = myTask.CreatedDate;

 
David Gunn 17David Gunn 17
Hmmm...I simplified the code to this and it compiles. I'll gradually build it out to the complete method that's getting the error and I'll be able to identify the problem.
 
public with sharing class myClass{
        Task myTask = new Task();
        DateTime myDate = myTask.CreatedDate;
    }
}

 
David Gunn 17David Gunn 17
The problem was that I had named my class Task.  Renamed it to TaskUtility and the error no longer happens.
This was selected as the best answer