You need to sign in to do that
Don't have an account?
Raghavendra M 13
How can i write the following code in VF Page and Apex class Save the Date in Background
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
try{
var accToUpdate = new sforce.SObject("Account");
accToUpdate.Id = "{!Account.Id}";
var today = new Date();
function fixTime(time){
if(time < 10) {time = "0" + time};
return time;
}
function fixDate(date){
var Month = fixTime(date.getMonth() + 1);
var Day = fixTime(date.getDate());
var UTC = date.toUTCString();
var Time = UTC.substring(UTC.indexOf(':')-2, UTC.indexOf(':')+6);
var Minutes = fixTime(date.getMinutes());
//var Seconds = fixTime(date.getSeconds());
return date.getFullYear() + "-" + Month + "-" + Day + "T" + Time;
}
accToUpdate.Current_Date__c = fixDate(today);
var result =
sforce.connection.update([accToUpdate]);
if(result[0].success == "true"){
location.reload();
}
else{
alert("An Error has Occurred. Error: " +
result[0].errors.message
);
}
}
catch(e){
alert(
"An Error has Occurred. Error: " +
e
);
}
try{
var accToUpdate = new sforce.SObject("Account");
accToUpdate.Id = "{!Account.Id}";
var today = new Date();
function fixTime(time){
if(time < 10) {time = "0" + time};
return time;
}
function fixDate(date){
var Month = fixTime(date.getMonth() + 1);
var Day = fixTime(date.getDate());
var UTC = date.toUTCString();
var Time = UTC.substring(UTC.indexOf(':')-2, UTC.indexOf(':')+6);
var Minutes = fixTime(date.getMinutes());
//var Seconds = fixTime(date.getSeconds());
return date.getFullYear() + "-" + Month + "-" + Day + "T" + Time;
}
accToUpdate.Current_Date__c = fixDate(today);
var result =
sforce.connection.update([accToUpdate]);
if(result[0].success == "true"){
location.reload();
}
else{
alert("An Error has Occurred. Error: " +
result[0].errors.message
);
}
}
catch(e){
alert(
"An Error has Occurred. Error: " +
e
);
}