Skip to Content

TheBlogReaders.com

Salesforce.com Learn & Share

Current DateTime Value to Javascript Salesforce Custom Button

Be First!
by December 4, 2018 SALESFORCE

Current DateTime Value to Javascript Salesforce Custom Button

To Get the Current DateTime value to Javascript Salesforce Custom Button

Current DateTime value to assign the Date Time Custom Field called “Created_Date_Time__c”.

{!REQUIRESCRIPT(“/soap/ajax/30.0/connection.js”)}
var createCase = new sforce.SObject(“Case”);
var todayDate = new Date();
createCase.Status = “Open”;
createCase.Created_Date_Time__c = todayDate.toJSON(); //DateTime Value
var caseInsrtResult = sforce.connection.create([createCase]);
window.location.reload();

Current Date value to assign the Date Time Custom Field called “Created_Date__c”.

{!REQUIRESCRIPT(“/soap/ajax/30.0/connection.js”)}
var createCase = new sforce.SObject(“Case”);
var todayDate = new Date();
createCase.Status = “Open”;
createCase.Created_Date__c = new Date().toISOString(); //Date Value
var caseInsrtResult = sforce.connection.create([createCase]);
window.location.reload();

Date and DateTime methods in Salesforce Apex Class
Example Apex Class to get the Date and DateTime values:

System.debug(‘Current Year::’ + Date.Today().Year());
System.debug(‘Current Month::’ + Date.Today().Month());
System.debug(‘Current Day::’ + Date.Today().Day());
System.debug(‘Yesterday Date::’ + Date.Today().addDays(-1));
System.debug(‘Tomorrow Date::’ + Date.Today().addDays(1));
System.debug(‘Today Date and Time::’ + DateTime.Now());

Output:

(3)

Previous
Next

Leave a Reply