You need to sign in to do that
Don't have an account?
Trouble updating an old S-Contol that used to work
For background, I'm not a programmer so "Hello World" is cutting edge for me. My goal is to have a detail page button that when pushed sets the custom field "Followup" to today+7days. The code below used to work for me, but some combination of browser / SF updates has left the code broken and useless.
Can anyone help me either fix the code below or offer an alternative suggestion for accomplishing my goal?
Thank you for your time.
-Derek
<html>
<head>
<script src="/soap/ajax/8.0/connection.js"
type="text/javascript"></script>
<script>
{
var sfaccount2 = new Date();
sfaccount2.setDate(sfaccount2.getDate()+7)
var accounts = sforce.connection.query("Select ID, Followup__c From Lead where Id = '{!Lead.Id}'");
var rec = accounts.getArray("records");
for (var i = 0;i<rec.length;i++) {
rec[i].Followup__c = sfaccount2;
}
sforce.connection.update(rec);
parent.window.close();
}
</script>
</head>
</body>
</html>
It looks like your detail page button is on the Lead page?
Try the following:
<script src="/soap/ajax/14.0/connection.js"></script> <script language="javascript"> var followUpDate = new Date(); followUpDate.setDate(followUpDate.getDate()+7); var leadId = "{!Lead.Id}"; var lead = new sforce.SObject("Lead"); var leadArray = []; lead.set("Id",leadId); lead.set("Followup__c",followUpDate); leadArray[0] = lead;
var saveResult = sforce.connection.update(leadArray); if(saveResult[0].getBoolean("success")==false) { alert("Error: " + saveResult); } else { parent.frames.location.replace("/{!Lead.Id}"); } </script>
For the custom button, set it as follows...
Behavior: Display in existing window with sidebar
Display Type: Detail Page Button
Content Source: Custom S-Control
As you gain programming experience, you may eventually want to move this over to a trigger.