I have created a custom detail button on Task. On click of the button I am calling URL like


I am getting the following error and following error displayed on the page:

Invalid date/time: 7/8/2016 10:32 PM



I need this Subject and LastModifiedDate in my controller to use.

Here is the code I am using to parse the Datetime

public class TaskController {
    public Datetime dt {get;set;}
    public TaskController() {
        dt =Datetime.valueof(ApexPages.currentPage().getParameters().get('last'));
  • 1
    Would it be possible to pass the Id of the task you were on, then perform a query for the relevant data in the constructor of your TaskController? This would eliminate the date/time formatting issue you are getting.
    – dsharrison
    Commented Jul 8, 2016 at 19:26
  • I need to show all the tasks with same subject and same createddate/lastmodifieddate.( tasks are generated from email to salesforce). so i need these parameters. Commented Jul 8, 2016 at 19:30

1 Answer 1


Use Datetime.parse instead of Datetime.valueOf, and it can handle the format you have provided. I used it in a sample page that mimics your own. Here was my constructor:

public TaskController()
    dt = Datetime.parse(ApexPages.currentPage().getParameters().get('last'));

Here was the output:

DEBUG|2016-07-09 04:32:00

Perhaps you need to do some work to get the time in the correct time zone. The following worked for me:

dt = Datetime.parse(ApexPages.currentPage().getParameters().get('last'));
dt = dt.newInstanceGmt(dt.date(), dt.time());

New output:

DEBUG|2016-07-08 22:32:00


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .