I created a JS button that creates an Opportunity and it populates certain fields with data from another Object (custom object called Deals). All the fields are working as they should except for CloseDate. The Opportunity CloseDate is of type Date and the CloseDate in Deal is of type Date as well.
However when I run:
newOpportunity.CloseDate = {!Deal_Registration__c.Close_Date__c};
It returns an error saying the format is wrong.(data shown below)
When I run
var curDate = new Date({!Deal_Registration__c.Close_Date__c});
newOpportunity.CloseDate = curDate;
It returns the wrong date. The Values I get back are:
When Deal CloseDate is equal to 03/04/2014
JS returns CloseDate in an alert() with 0.0003723932472691162
and curDate returns Wed Dec 31 1969 19:00:00 GMT-0500 (EST)
Any help would be greatly appreciated, I tried to follow the answer to Date coming back in wrong format using JS remoting. but as shown above I get the wrong date returned
Attribution to: jnoel10
Possible Suggestion/Solution #1
It looks like your JavaScript is interpreting your date as an equation; 3 divided by 4 divided by 2014 is 0.000372....
I think you need to add quotes to your statement. Instead of
var curDate = new Date({!Deal_Registration__c.Close_Date__c});
try
var curDate = new Date('{!Deal_Registration__c.Close_Date__c}');
That should cause the emitted script to be a string and interpreted correctly.
Attribution to: Mike Chale
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/33701