function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

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.




<script src="/soap/ajax/8.0/connection.js"
var sfaccount2 = new Date();


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;






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.

Excellent. Thank you very much!