You need to sign in to do that
Don't have an account?

PLEASE HELP!!!
Please Help....
I am getting the error "object expected" on line in red. What I have to do to fix it?
====================================================
<html>
<head>
<script src="/soap/ajax/9.0/connection.js"></script>
<script src="https://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js" type="text/javascript"></script>
<script language="javascript">
<head>
<script src="/soap/ajax/9.0/connection.js"></script>
<script src="https://www.salesforce.com/services/lib/ajax/beta3.3/sforceclient.js" type="text/javascript"></script>
<script language="javascript">
function do_code()
{
{
sforceClient.init("{!API.Session_ID}", "{!API.Partner_Server_URL_70}", false);
var accountid = "{!TH_Distributor_Recap__c.DistributorId__c}";
var thdist = "{!TH_Distributor_Recap__c.Id}";
var thdist = "{!TH_Distributor_Recap__c.Id}";
var qrdr = sforce.connection.query("Select BillingStreet, BillingCity, BillingState, Distributor_Type__c from Account where id = '" + accountid + "'");
var records = qrdr.getArray("records");
alert(records.length);
alert(thdist);
for (var i = 0; i < records.length; i++)
{
tt = records[i];
var BillingStreet=tt.get("BillingStreet");
var BillingCity = tt.get("BillingCity");
var BillingState= tt.get("BillingState");
var Distributor_Type__c= tt.get("Distributor_Type__c");
}
alert(BillingStreet);
alert(BillingCity);
alert(BillingState);
alert(Distributor_Type__c);
alert(records.length);
alert(thdist);
for (var i = 0; i < records.length; i++)
{
tt = records[i];
var BillingStreet=tt.get("BillingStreet");
var BillingCity = tt.get("BillingCity");
var BillingState= tt.get("BillingState");
var Distributor_Type__c= tt.get("Distributor_Type__c");
}
alert(BillingStreet);
alert(BillingCity);
alert(BillingState);
alert(Distributor_Type__c);
///////////////////// update item//////////////////////////////////////////////
var thUpdate = new Array();
alert("1 - So far so good");
var thObject = new sforce.DynaBean("TH_Distributor_Recap__c");
alert("2 - So far so good");
thObject.set("Id", thdist);
thObject.set("Distributor_Address__c", BillingStreet);
thObject.set("Distributor_City__c", BillingCity);
thObject.set("Distributor_State__c", BillingState);
thObject.set("Distributor_Type__c", Distributor_Type__c);
thUpdate.push(thObject);
var update = sforceClient.Update(thUpdate);
parent.location.href = "{!TH_Distributor_Recap__c.Link}";
//////////////////////////////////////////////////////////////////////////////////////////
}
var thUpdate = new Array();
alert("1 - So far so good");
var thObject = new sforce.DynaBean("TH_Distributor_Recap__c");
alert("2 - So far so good");
thObject.set("Id", thdist);
thObject.set("Distributor_Address__c", BillingStreet);
thObject.set("Distributor_City__c", BillingCity);
thObject.set("Distributor_State__c", BillingState);
thObject.set("Distributor_Type__c", Distributor_Type__c);
thUpdate.push(thObject);
var update = sforceClient.Update(thUpdate);
parent.location.href = "{!TH_Distributor_Recap__c.Link}";
//////////////////////////////////////////////////////////////////////////////////////////
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body onLoad="do_code();">
</body>
</html>
</body>
</html>
For example, you're bringing in /soap/ajax/9.0/connection.js, and yet you're doing the init call with the sforceClient.init construct which is no longer needed. Likewise your update call is probably not correct.
Dynabeans are also 3.3 Beta, you probably want:
var thObject = new sforce.SObject("TH_Distributor_Recap__c");
I suggest you read the Migrating from the Beta Ajax Toolkit section from the latest API doc.
Lastly, I would suggest putting some Try/Catch blocks around your code.
Lastly (again), I think your logic is a little goofy. If you return more than one record in your query, you seem to be ignoring them all except the last one. Perhaps by design or for debugging. But, if that's your goal you can use the "limit" qualifier on the query to only return one row.
Best of luck, Steve.