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


Please Help....
I am getting the error "object expected" on line in red. What I have to do to fix it?
<script src="/soap/ajax/9.0/connection.js"></script>
<script src="" 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 qrdr = sforce.connection.query("Select BillingStreet, BillingCity, BillingState, Distributor_Type__c from Account where id = '" + accountid + "'");        
var records = qrdr.getArray("records");
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");
///////////////////// 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);
var update = sforceClient.Update(thUpdate);
parent.location.href = "{!TH_Distributor_Recap__c.Link}";

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<body onLoad="do_code();">
try this
var thObject = new Sforce.DynaBean("TH_Distributor_Recap__c");
(Just use the "S" instead of "s"). Let me know if still not working.
Thanks. It works!!!
Without trying it, just visual inspection, I think you are running into problems because you're mixing 3.3Beta and Production calls for the Ajax Toolkit.

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.

Thank you for very good points!!!!.
I was able to eliminate the code lines I don't need.