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
benfishinbenfishin 

Creating a DynaBean

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Create Lead</title>

<script src="http://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js" type="text/javascript"></script>
<link href="/css/ie_global.css" rel="stylesheet" type="text/css">
<link href="/css/ie_navigation.css" rel="stylesheet" type="text/css">
<link href="/css/opportunities_styles.css" rel="stylesheet" type="text/css">
<script language="javascript">
function initPage() {
//Get Salesforce connection based on users current session id
sforceClient.init("{!API_Session_ID}", "{!API_Partner_Server_URL_60}");
window.setTimeout(";", 1000);

var phone = "{!Contact_Phone}";
if (phone == "") {
  phone = "{!Account_Phone}";
}

var lead = new DynaBean("Lead");
lead.set("FirstName", "{!Contact_FirstName}");
lead.set("LastName", "{!Contact_LastName}");
lead.set("Title", "{!Contact_Title}");
lead.set("Email", "{!Contact_Email}");
lead.set("Phone", phone);
lead.set("MobilePhone", "{!Contact_MobilePhone}");
lead.set("Company", "{!Account_Name}");
lead.set("Website", "{!Account_Website}");
lead.set("Street", "{!Account_ShippingStreet}");
lead.set("City", "{!Account_ShippingCity}");
lead.set("State", "{!Account_ShippingState}");
lead.set("PostalCode", "{!Account_ShippingPostalCode}");
lead.set("Country", "{!Account_ShippingCountry}");

var saveResult = sforceClient.Create(lead)[0];

document.getElementById("divErrorMsg").innerHTML = saveResult.toString();
document.getElementById("divErrorMsg").style.display = "";
}
</script>
</head>
<body onload="initPage();">
<div id="divErrorMsg"></div>
</body>
</html>

 
Trying to folllow the example in the Sforce AJAX Toolkit beta1 doc. I get the following error.
 
 
What am I missing?
 
Thanks
 
gsickalgsickal
prefix the Dynabean with Sforce as in
var lead = new Sforce.Dynabean("Lead");
benfishinbenfishin
I got:
 
DevAngelDevAngel
var contact = new Sforce.Dynabean("contact");
gsickalgsickal

the "b" in Dynabean is is case-sensitive, it should be "new Sforce.Dynabean", not "new Sforce.DynaBean"

benfishinbenfishin

Many thanks to gsickal and DevAngel .

The issue was:

var lead = new Sforce.Dynabean("Lead");  //Note: case sensitive and not the same case in the Sforce Ajax Toolkit beta 1 doc. (I am using beta 3 in this code).

The following appears to work (I still have some stress testing to do). Hope this sheds some light for anyone else trying to accomplish something similar. Please let me know if you if you figure out some fancier DHTML or error handeling.

-BenFishin 

 

Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Create Lead</title>
<div id="accountShippingStreet" style="position:absolute; visibility:hidden;">{!Account_ShippingStreet}</div>
<script src="http://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js" type="text/javascript"></script>
<script language="javascript">
function initPage() {
//Get Salesforce connection based on users current session id
sforceClient.init("{!API_Session_ID}", "{!API_Partner_Server_URL_60}");
window.setTimeout(";", 1000);

var phone = "{!Contact_Phone}";
if (phone == "") {
  phone = "{!Account_Phone}";
}
var accountShippingStreet = document.getElementById('accountShippingStreet').innerHTML;

var lead = new Sforce.Dynabean("Lead");
lead.set("FirstName", "{!Contact_FirstName}");
lead.set("LastName", "{!Contact_LastName}");
lead.set("Title", "{!Contact_Title}");
lead.set("Email", "{!Contact_Email}");
lead.set("Phone", phone);
lead.set("MobilePhone", "{!Contact_MobilePhone}");
lead.set("Company", "{!Account_Name}");
lead.set("Website", "{!Account_Website}");
lead.set("Street", accountShippingStreet);
lead.set("City", "{!Account_ShippingCity}");
lead.set("State", "{!Account_ShippingState}");
lead.set("PostalCode", "{!Account_ShippingPostalCode}");
lead.set("Country", "{!Account_ShippingCountry}");

var saveResult = sforceClient.Create(lead)[0];

top.location.replace("/" + saveResult.id + "/e—retURL=%2F" + saveResult.id);

}
</script>
</head>
<body onload="initPage();">
<table width="100%">
    <tr><td width="100%" align="center"><br><br><br>Please wait, records are being updated&hellip;<br><br>
    <img src="/img/waiting_dots.gif" border="0" width=156 height=34></td></tr>
</table>
</body>
</html>


 

Mike ShawalukMike Shawaluk
I've been searching these forums after being absent for a while, looking for documentation on the changes that took place with beta3 of the AJAX toolkit. It appears to be up to beta3.3 by now? Or is there a released version?

I have been using the toolkit since the first beta & have gone through several upgrades already, but I've never encountered a rewrite of the "getting started" doc that came with the first beta. Most of the information in that older document is no longer correct. Is there any information besides the "autodocs"?

Thanks,

  - Mike
Ron HessRon Hess
3.3 is it, latest and greatest

The best doc is the stuff bundeled with the eclipse AppExchange plug-in.

download Eclipse, then add the AppExchange stuff, ( instructions are on the appex developer network) then click help, find the AppExchange help docs and start searching / reading...

it's mostly autodoc, but is searchable and the s-control editing features of this combo are very slick.