[SalesForce] Why does it say “DateTime does not exist”

Apex Code

public class TaskTriggerHelper {
   public TaskTriggerHelper(){

   }
   public static void createTask(list<Task> tskList){
    list<task> listOfTask = new list<task>();
    for(task tsk : tskList){
       DateTime myDateTime = DateTime.newInstance(task.ActivityDate,0,0,0); 
    } 
   }
 }

Best Answer

If you want to use the newInstance method, there are many signatures defined, but not the one you are trying to use:

  • newInstance(milliseconds)
    Constructs a Datetime and initializes it to represent the specified number of milliseconds since January 1, 1970, 00:00:00 GMT.
  • newInstance(date, time)
    Constructs a DateTime from the specified date and time in the local time zone.
  • newInstance(year, month, day)
    Constructs a Datetime from Integer representations of the specified year, month (1=Jan), and day at midnight in the local time zone.
  • newInstance(year, month, day, hour, minute, second)
    Constructs a Datetime from Integer representations of the specified year, month (1=Jan), day, hour, minute, and second in the local time zone.

If you already have a date, the simplest would be:

Datetime.newInstance(myDate, Time.newInstance(0,0,0,0))
Related Topic