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
AVictorioAVictorio 

Lead: Custom Link S-Control to Update Field

Hello out there.  I think I've read every post and just about all documentation I could on the Ajax tool kit and Eclipse.  I'm not a programer by any means so please bear with me as I'm just looking for some guidance.

I'm trying to set up an S-Control that I can call using a custom link on the Lead object.

I need the S-Control to update custom field "Queue__c" with the string value "SupplierRelations". (simple right?)

Below is the code I'm using but I cannot for the life of me get it to work.  Can someone please tell me what I'm doing wrong?

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
<html> 
<head> 
<title></title> 
<script language="javascript" src="https://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js—browser=true" type="text/javascript"></script> 
<script id="clientEventHandlersJS" language="javascript"> 
<!-- 
function initPage() { 
sforceClient.registerInitCallback(setup); 
sforceClient.setLoginUrl("https://www.salesforce.com/services/Soap/u/7.0"); 
sforceClient.init("{!API_Session_ID}", "{!API_Partner_Server_URL_70}", true); 
} 

//Use this function as the entry point for your DHTML and JAVASCRIPT processing 
function setup() { 
var lead = new Sforce.Dynabean("Lead") 
lead.set("Queue__c","SupplierRelations"); 
lead.save(); 
} 

//--> 
</script> 
</head> 
<body onload="initPage()"> 
</body> 
</html>
hemmhemm
  • You need a semi-colon ; at the end of var lead = new Sforce.Dynabean("Lead")
  • Make sure you are populating all of the required fields before you save the record.
Use var saveResult = lead.save(); to get the result of the save method and see if it was successful.
AVictorioAVictorio

Code:

<html> 
<head> 
<title></title> 
<script language="javascript" src="https://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js" type="text/javascript"></script> 

<script id="clientEventHandlersJS" language="javascript"> 

function initPage() { 
sforceClient.registerInitCallback(setup); 
sforceClient.setLoginUrl("https://www.salesforce.com/services/Soap/u/7.0"); 
sforceClient.init("{!API_Session_ID}", "{!API_Partner_Server_URL_70}", true); 
} 

function CloseReload() { 
window.opener.location.reload(); 
window.close(); 
} 

function setup() { 
var lead = new Sforce.Dynabean("lead"); 
lead.set ("Queue__c", "SupplierRelations"); 
var saveResult = lead.save(); 
CloseReload(); 
} 

</script> 
</head> 
<body onload="initPage()"> 
</body> 
</html>


 
I must still be doing something wrong (sorry to be such a newbie!).  Above is the code I tried and it seems to run its course but nothing gets updated.  Any suggestions? 

hemmhemm
Company and Last Name are both required on insert of a Lead record..  Try adding the following to test it out.

lead.set ("Company", "Company ABC"); 
lead.set ("LastName", "Test");

Ron HessRon Hess
try adding code to check the save result

alert ( saveResult.toString() )

to see what is going on with your call to the toolkit / API