1

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

/apex/TaskVF?subject={!Task.Subject}&LastModifiedDate={!Task.LastModifiedDate}.

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

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

Url:

/apex/TaskVF?subject=Call&last=7%2F8%2F2016+10%3A32+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'));
    }
}
2
  • 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

2

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'));
    system.debug(dt);
}

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

0

You must log in to answer this question.

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