Hello stackexchange gurus.

I have a problem with setting a future Due Date for a task using javascript in Salesforce. Below is the piece of code i use:

var d = new Date();
    var date =(d.getDate()+"/"+(d.getMonth()+1)+"/"+d.getFullYear()).dateFormat;
    taskToCreate.ActivityDate = date;

Unfortunately, the result of this code is empty "Due Date" field. In case i get rid of .dateFormat, the error will appear, saying something like "incorrect value format for required field".

In case there is a simplier solution for setting Due Date as "7 days from today's date", i'd be grateful if you share your knowledge.

I was unable to find the answer on my own, and i will really appreciate any advice on that issue.

Thank you in advance, Best Regards.

  • I'm not a specialist of javascript, but is it normal to have quote on the last line ? Jan 12, 2015 at 14:02
  • Hi Yann G. That was an old bit of code, the one i'm using in SF is without quotes (but still with the same result). Thanks fo noticing that, will change it in the main message.
    – Emilio
    Jan 12, 2015 at 14:05
  • Have you tried to format this date format : var date =d.getFullYear() + "-" + (d.getMonth()+1)+ "-" + d.getDate(); Jan 12, 2015 at 14:23
  • When i manually add a date to a field, the date separator is "/" (also thats how the date is presented in SF, e.g. 23/01/2015). I also tried to switch places of month/day (UK and US version), but that wasnt the case, got the same result..
    – Emilio
    Jan 12, 2015 at 14:45
  • 1
    check out the solution for this question salesforce.stackexchange.com/questions/17644/….. You can use sforce.internal.dateTimeToString(new Date()) function to the work done.
    – Sam
    Jan 12, 2015 at 15:10

1 Answer 1


Managed to solve the issue by changing the code to this:

var d = new Date();
var date1 =((d.getMonth()+1)+"/"+d.getDate()+"/"+d.getFullYear());
taskToCreate.ActivityDate = new Date(date1);

Thanks everybody who spent their time to go through the question!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.